Skip to content

Commit

Permalink
fix: format and move to folder
Browse files Browse the repository at this point in the history
  • Loading branch information
vinckr committed Jul 19, 2023
1 parent b5c1e7c commit b48cfab
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 21 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit b48cfab

Please sign in to comment.