diff --git a/ory-action-vpncheck-py/.gitignore b/ory-actions/vpncheck-py/.gitignore similarity index 100% rename from ory-action-vpncheck-py/.gitignore rename to ory-actions/vpncheck-py/.gitignore diff --git a/ory-action-vpncheck-py/README.md b/ory-actions/vpncheck-py/README.md similarity index 72% rename from ory-action-vpncheck-py/README.md rename to ory-actions/vpncheck-py/README.md index 1e0726f..cf28292 100644 --- a/ory-action-vpncheck-py/README.md +++ b/ory-actions/vpncheck-py/README.md @@ -11,40 +11,40 @@ It's intended for use as a post-login Action on Ory Network and returns a message that can be parsed by Ory and displayed to the user. The example implementation is written in Python with Flask for deployment on GCP -Cloud Functions, and can easily be adapted for different scenarios. +Cloud Functions, and can be adapted for different scenarios. -## How to run it +## Develop -### You'll need - -Accounts: +### Prerequisites - A Google Cloud project with Cloud Functions active (or an alternate way to deploy) - A vpnapi.com account +- python 3.9+ with flask, requests, google cloud logging -For Development: +To install dependencies, run e.g. -- python 3.9+ -- flask -- requests -- google cloud logging +```bash +pip3 install flask +pip3 install google-cloud-logging +``` -To install dependencies, run e.g. +### Environmental Variables ```bash - pip3 install google-cloud-logging +export BEARER_TOKEN=SOME_SECRET_API_KEY_FOR_YOUR_WEBHOOK; +export VPNAPIIO_API_KEY=YOUR_VPNAPI_KEY; +python3 main.py ``` ### Run locally ```bash - export BEARER_TOKEN=SOME_SECRET_API_KEY_FOR_YOUR_WEBHOOK; - export VPNAPIIO_API_KEY=YOUR_VPNAPI_KEY; - python3 main.py +cd ory-actions/vpncheck-py +python3 main.py ``` -### Send a sample request +#### Send a sample request ```bash curl -X POST \ @@ -62,14 +62,14 @@ For blocked requests, you'll get `HTTP 400` responses with a payload like When successful, you'll get a `HTTP 200` response. -## Deploy to GCP +## Deploy After setting up your GCP project (see, for example, [this guide](https://cloud.google.com/functions/docs/create-deploy-http-python)), you can deploy the Action as a cloud function: ```bash - gcloud functions deploy vpncheck --runtime python39 --trigger-http --allow-unauthenticated --set-env-vars BEARER_TOKEN=$SOME_SECRET_API_KEY_FOR_YOUR_WEBHOOK,VPNAPIIO_API_KEY=$VPNAPIIO_API_KEY,ENABLE_CLOUD_LOGGING=true --source=. +gcloud functions deploy vpncheck --runtime python39 --trigger-http --allow-unauthenticated --set-env-vars BEARER_TOKEN=$SOME_SECRET_API_KEY_FOR_YOUR_WEBHOOK,VPNAPIIO_API_KEY=$VPNAPIIO_API_KEY,ENABLE_CLOUD_LOGGING=true --source=. ``` Note: You may need to create a `venv` for dependencies to load correctly. @@ -78,7 +78,7 @@ You'll receive an endpoint address, which you can plug into the `curl` command above. On Google's Cloud Console, you can also see logs to verify it's working as intended. -## Integrating with Ory +### Integrating with Ory To set up your Ory Network project to use the Action, go to Ory Console > Developers > Actions and create a new post-login webhook: @@ -111,10 +111,21 @@ the IP address from the context with a simple JSONNET transformation: ![Console Actions Screen](docs/images/actions-console-3.png) -## Seeing it in action +### Seeing it in action With everything set up, we can test the behavior using the Ory Account Experience. When logging in via VPN, the request now gets blocked and the message is shown to users! ![Account Experience displaying error](docs/images/ax-with-message.png) + +## Contribute + +Feel free to +[open a discussion](https://github.com/ory/examples/discussions/new) to provide +feedback or talk about ideas, or +[open an issue](https://github.com/ory/examples/issues/new) if you want to add +your example to the repository or encounter a bug. You can contribute to Ory in +many ways, see the +[Ory Contributing Guidelines](https://www.ory.sh/docs/ecosystem/contributing) +for more information. diff --git a/ory-action-vpncheck-py/docs/images/actions-console-1.png b/ory-actions/vpncheck-py/docs/images/actions-console-1.png similarity index 100% rename from ory-action-vpncheck-py/docs/images/actions-console-1.png rename to ory-actions/vpncheck-py/docs/images/actions-console-1.png diff --git a/ory-action-vpncheck-py/docs/images/actions-console-2.png b/ory-actions/vpncheck-py/docs/images/actions-console-2.png similarity index 100% rename from ory-action-vpncheck-py/docs/images/actions-console-2.png rename to ory-actions/vpncheck-py/docs/images/actions-console-2.png diff --git a/ory-action-vpncheck-py/docs/images/actions-console-3.png b/ory-actions/vpncheck-py/docs/images/actions-console-3.png similarity index 100% rename from ory-action-vpncheck-py/docs/images/actions-console-3.png rename to ory-actions/vpncheck-py/docs/images/actions-console-3.png diff --git a/ory-action-vpncheck-py/docs/images/ax-with-message.png b/ory-actions/vpncheck-py/docs/images/ax-with-message.png similarity index 100% rename from ory-action-vpncheck-py/docs/images/ax-with-message.png rename to ory-actions/vpncheck-py/docs/images/ax-with-message.png diff --git a/ory-action-vpncheck-py/main.py b/ory-actions/vpncheck-py/main.py similarity index 98% rename from ory-action-vpncheck-py/main.py rename to ory-actions/vpncheck-py/main.py index c848dd8..5aff0b9 100644 --- a/ory-action-vpncheck-py/main.py +++ b/ory-actions/vpncheck-py/main.py @@ -55,7 +55,7 @@ def vpncheck(request): # Check the response from vpnapi.io if "error" in vpn_result and vpn_result["error"] == "Blocked": - return error_response("Request blocked: Blocked by vpn api") + return error_response("Request blocked: Blocked by VPN API") if "security" in vpn_result: security_info = vpn_result["security"] diff --git a/ory-action-vpncheck-py/package.json b/ory-actions/vpncheck-py/package.json similarity index 100% rename from ory-action-vpncheck-py/package.json rename to ory-actions/vpncheck-py/package.json diff --git a/ory-action-vpncheck-py/requirements.txt b/ory-actions/vpncheck-py/requirements.txt similarity index 100% rename from ory-action-vpncheck-py/requirements.txt rename to ory-actions/vpncheck-py/requirements.txt