Skip to content

Commit

Permalink
Merge pull request #36 from vzakharchenko/updated_serverless_client
Browse files Browse the repository at this point in the history
updated example with Entitlement Type
  • Loading branch information
vzakharchenko committed Apr 23, 2021
2 parents 38fdf4c + 43bc762 commit 7229b6b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 48 deletions.
Binary file added docs/allAccess.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/jwksonly1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/jwksonly2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/keycloakCrossClientAuthorization.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/keycloakCrossClientAuthorization2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/noLambdas.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 14 additions & 8 deletions example/keycloak-authorizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,28 @@ Permissions:
| UI Permission | uiRolePermission | uiRolePolicy | uiResource | Access To UI |
| Lambda Permission | lambdaPermission | lambdaPolicy | LambdaResource | Permission To Invoke Lambda |

## 5. Results
## 5. Entitlement Types
### 5.1 Client Side
![](../../docs/keycloakCrossClientAuthorization.png)
### 5.2 Serverless side
![](../../docs/keycloakCrossClientAuthorization2.png)

## 6. Results

| User | Result | Description |
|:----------|:-------------------------------------------------------------------------------------------------------|:------------------------------------------------------|
| User | ![Express handlebars 2020-04-12 12-54-06](../../docs/Express%20handlebars%202020-04-12%2012-54-06.png) | All Access |
| user-jwks | ![Express handlebars 2020-04-12 12-56-22](../../docs/Express%20handlebars%202020-04-12%2012-56-22.png) | lambda-jwks only |
| User2 | ![Express handlebars 2020-04-11 22-45-33](../../docs/Express%20handlebars%202020-04-12%2012-57-43.png) | Has access to UI but does not have access to Lambda`s |
| User | ![Express handlebars 2020-04-12 12-54-06](../../docs/allAccess.png) | All Access |
| user-jwks | ![Express handlebars 2020-04-12 12-56-22](../../docs/jwksonly1.png) ![Express handlebars 2020-04-12 12-56-22](../../docs/jwksonly2.png) | lambda-jwks only |
| User2 | ![Express handlebars 2020-04-11 22-45-33](../../docs/noLambdas.png) | Has access to UI but does not have access to Lambda`s |
| User3 | ![localhost3001+2020-04-11+22-47-30](../../docs/localhost3001%2B2020-04-11%2B22-47-30.png) | Does not have access to UI and Lambda`s |

## 6. Deploy to cloud
### 6.1 Run Keycloak with ngrok
## 7. Deploy to cloud
### 7.1 Run Keycloak with ngrok
```console
ngrok http 8080
```
![vzakharchenko14-32-39](../../docs/vzakharchenko14-32-39.png)
### 6.2 Modify keycloak.json with a new host
### 7.2 Modify keycloak.json with a new host

example/keycloak-authorizer/ui/keycloak.json
```json
Expand Down Expand Up @@ -138,7 +144,7 @@ example/resources/keycloak.json
}
```

### 6.1 Deploy Lambda`s
### 7.2 Deploy Lambda`s
- deploy serverless
```bash
cd serverless
Expand Down
77 changes: 39 additions & 38 deletions example/keycloak-authorizer/ui/restCalls.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
const fetch = require('axios');
fetch.interceptors.response.use(response=>response, error => error)

function fetchData(url, method = 'GET', headers) {
return new Promise((resolve, reject) => {
fetch({
url,
method,
headers,
transformResponse: req => req,
withCredentials: true,
timeout: 29000,
}).then((response) => {
if (response.isAxiosError){
reject(response.message);
}
resolve(response.data);
}).catch((response) => {
reject(response);
});
fetch.interceptors.response.use((response) => response, (error) => error);

function fetchData(url, method = 'GET', headers) {
return new Promise((resolve, reject) => {
fetch({
url,
method,
headers,
transformResponse: (req) => req,
withCredentials: true,
timeout: 29000,
}).then((response) => {
if (response.isAxiosError) {
reject(response.message);
}
resolve(response.data);
}).catch((response) => {
reject(response);
});
});
}

function sendData(url, method = 'POST', data, headers) {
return new Promise((resolve, reject) => {
fetch({
url,
method,
data,
headers,
transformResponse: req => req,
withCredentials: true,
timeout: 29000,
}).then((response) => {
if (response.isAxiosError){
reject(response.message);
}
resolve(response.data);
}).catch((response) => {
reject(response);
});
function sendData(url, method = 'POST', data, headers) {
return new Promise((resolve, reject) => {
fetch({
url,
method,
data,
headers,
transformResponse: (req) => req,
withCredentials: true,
timeout: 29000,
}).then((response) => {
if (response.isAxiosError) {
reject(response.message);
}
resolve(response.data);
}).catch((response) => {
reject(response);
});
});
}

module.exports = {
fetchData,
sendData
fetchData,
sendData,
};
2 changes: 1 addition & 1 deletion example/keycloak-authorizer/ui/views/home.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<th>Lambda url</th>
<th>Client Name</th>
<th>Credential Type</th>
<th>Entitlement</th>
<th>Entitlement Type</th>
<th>Invoke Lambda</th>
<th>Lambda Response</th>
<th>Access Token</th>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "keycloak-lambda-authorizer",
"version": "0.3.8",
"version": "0.4.0",
"description": "Keycloak adapter for aws Lambda",
"main": "index.js",
"homepage": "https://github.com/vzakharchenko/keycloak-lambda-authorizer",
Expand Down

0 comments on commit 7229b6b

Please sign in to comment.