Skip to content

Commit

Permalink
Removed shell scripts and replaced them with a postman configuration …
Browse files Browse the repository at this point in the history
…and updated readme instructions.
  • Loading branch information
t-burch committed Oct 30, 2023
1 parent f5c420b commit 843e15e
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 76 deletions.
19 changes: 18 additions & 1 deletion distribution/examples/oauth2/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,21 @@

This example shows the OAuth2 password flow. A client requests an access token ( with user credentials ) and the token is verified through a token validator.

Please follow https://www.membrane-soa.org/api-gateway-doc/current/oauth2-password-flow-sample.html

## Running the example

### Setup

1. Go to the [Postman](https://www.postman.com/downloads/) website and install the latest desktop client for your OS.
2. Open the Postman app and drag `environment.json` and `requests.json` into the menu bar to the right.
3. Click on the `environments` tab and tick the checkmark on the `oauth2 environment`.
4. Click on the `collections` tab and open the `oauth2 example requests` folder.

### Sending the Requests

1. Click on the `POST` request and press `Send`. This will request an oauth token from the authorization server using the username `john` and password `password`.
2. Click on the `GET` request and send it. Now the previously acquired oauth token will be set in the `Authorization` header using the `Bearer` keyword to authenticate with the token validator.

See:
- [oauth2authserver](https://www.membrane-soa.org/api-gateway-doc/5.2/configuration/reference/oauth2authserver.htm) reference
- [tokenValidator](https://www.membrane-soa.org/api-gateway-doc/5.2/configuration/reference/tokenValidator.htm) reference
1 change: 0 additions & 1 deletion distribution/examples/oauth2/api/client.bat

This file was deleted.

38 changes: 0 additions & 38 deletions distribution/examples/oauth2/api/client.ps1

This file was deleted.

36 changes: 0 additions & 36 deletions distribution/examples/oauth2/api/client.sh

This file was deleted.

15 changes: 15 additions & 0 deletions distribution/examples/oauth2/api/environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "c36d2677-2ff1-4e07-be96-54919137ef0f",
"name": "oauth2 environment",
"values": [
{
"key": "accessToken",
"value": "",
"type": "secret",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2023-10-30T10:00:15.840Z",
"_postman_exported_using": "Postman/10.19.10"
}
101 changes: 101 additions & 0 deletions distribution/examples/oauth2/api/requests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"info": {
"_postman_id": "27c65ce6-2e99-49ee-8f2c-8b501b476058",
"name": "oauth2 example requests",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "30827720"
},
"item": [
{
"name": "http://localhost:7007/oauth2/token",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = pm.response.json();\r",
"pm.environment.set(\"accessToken\", jsonData.access_token);\r",
"pm.environment.set(\"tokenType\", jsonData.token_type);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "grant_type",
"value": "password",
"type": "text"
},
{
"key": "username",
"value": "john",
"type": "text"
},
{
"key": "password",
"value": "password",
"type": "text"
},
{
"key": "client_id",
"value": "abc",
"type": "text"
},
{
"key": "client_secret",
"value": "def",
"type": "text"
}
]
},
"url": {
"raw": "http://localhost:7007/oauth2/token",
"protocol": "http",
"host": [
"localhost"
],
"port": "7007",
"path": [
"oauth2",
"token"
]
},
"description": "1.) Requesting Token"
},
"response": []
},
{
"name": "http://localhost:2000",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{accessToken}}",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:2000",
"protocol": "http",
"host": [
"localhost"
],
"port": "2000"
},
"description": "2.) Calling API"
},
"response": []
}
]
}

0 comments on commit 843e15e

Please sign in to comment.