Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #29

Merged
merged 78 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
4e6b9eb
Fix develop dockerfile
daniel-pimenta-DME Jul 5, 2023
918d4c6
Change keycloak urls
daniel-pimenta-DME Jul 5, 2023
ba4b8b6
Fix develop workflow tag
daniel-pimenta-DME Jul 5, 2023
5796045
Fix production workflow
daniel-pimenta-DME Jul 5, 2023
9f4d9c2
Change log message
daniel-pimenta-DME Jul 5, 2023
45704b4
Change config
daniel-pimenta-DME Jul 5, 2023
8fefb80
Add health check
daniel-pimenta-DME Jul 5, 2023
e2b6f3f
Fix health check
daniel-pimenta-DME Jul 5, 2023
e9b702d
Add ready health endpoint
daniel-pimenta-DME Jul 5, 2023
7ad7d20
Fix issue
daniel-pimenta-DME Jul 5, 2023
94c2d7e
Change workflow filenames
daniel-pimenta-DME Jul 5, 2023
4667b27
Eoepca 910 um keycloak develop an identity api based on keycloak api …
flaviorosadme Jul 25, 2023
e8f2581
Update README
daniel-pimenta-DME Aug 21, 2023
7726408
Merge branch 'develop' of https://github.com/EOEPCA/um-identity-api i…
daniel-pimenta-DME Aug 21, 2023
6743f64
Update config
daniel-pimenta-DME Sep 26, 2023
f9c6a84
Update config
daniel-pimenta-DME Sep 26, 2023
8468ce0
Update config
daniel-pimenta-DME Sep 26, 2023
c170db2
Api testing (#18)
flaviorosadme Oct 9, 2023
cf2d35a
Update ci
daniel-pimenta-DME Oct 10, 2023
5eecb1e
Update ci
daniel-pimenta-DME Oct 10, 2023
b6a0828
Release v1.0.0
daniel-pimenta-DME Oct 15, 2023
197b1c0
Fix ci
daniel-pimenta-DME Oct 15, 2023
85b8f27
Fix requirements
daniel-pimenta-DME Oct 15, 2023
5aace57
Fix ci
daniel-pimenta-DME Oct 15, 2023
f0ac15a
Merge branch 'master' into develop
daniel-pimenta-DME Oct 15, 2023
e5559d5
Upgrade flask version
daniel-pimenta-DME Oct 15, 2023
b86284c
Merge branch 'develop' of https://github.com/EOEPCA/um-identity-api i…
daniel-pimenta-DME Oct 15, 2023
df2ec57
Update requirements
daniel-pimenta-DME Oct 15, 2023
de3ee6c
Merge branch 'master' into develop
daniel-pimenta-DME Oct 15, 2023
c19db10
feat: added error handling (#23)
flaviorosadme Oct 16, 2023
7fda506
feat: added validator of register and protect resource enpoint to test
flaviorosadme Oct 18, 2023
9d51ae6
Merge branch 'develop' of https://github.com/EOEPCA/um-identity-api i…
flaviorosadme Oct 18, 2023
ffe7a1d
feat: register and protect resources endpoint working
flaviorosadme Oct 19, 2023
a8c62a6
feat: added delete resources, policies and permissions
flaviorosadme Oct 20, 2023
734244e
Update ci
daniel-pimenta-DME Oct 23, 2023
2de9bfd
Merge branch 'develop' of https://github.com/EOEPCA/um-identity-api i…
daniel-pimenta-DME Oct 23, 2023
acc4fed
Update ci
daniel-pimenta-DME Oct 23, 2023
004b489
Fix ci
daniel-pimenta-DME Oct 24, 2023
9d8c034
Add options method to endpoints
daniel-pimenta-DME Oct 29, 2023
e5cdcae
Merge branch 'master' into develop
daniel-pimenta-DME Oct 29, 2023
82a5a5f
feat: added endpoint to create client, add resources and protect them…
flaviorosadme Nov 8, 2023
9ad30a0
Merge branch 'develop' of https://github.com/EOEPCA/um-identity-api i…
flaviorosadme Nov 8, 2023
deb3afe
Revert "Add options method to endpoints"
flaviorosadme Nov 8, 2023
63089e0
Merge remote-tracking branch 'origin/master' into develop
flaviorosadme Nov 8, 2023
b3514a6
fea: commit fixes
flaviorosadme Nov 8, 2023
2d6426c
feat: more fixes, some endpoint were dounbled
flaviorosadme Nov 8, 2023
8d77748
fix: last fix
flaviorosadme Nov 8, 2023
7d57858
Update ci
daniel-pimenta-DME Nov 9, 2023
928816d
Merge branch 'develop' of https://github.com/EOEPCA/um-identity-api i…
daniel-pimenta-DME Nov 9, 2023
11cae2f
fix: policies fix, response now return client id and resources created
flaviorosadme Nov 10, 2023
31e1db0
feat: create client default to confidential and authorization enabled
flaviorosadme Nov 14, 2023
9d3aae1
Convert to FastAPI
daniel-pimenta-DME Nov 14, 2023
8a8dba0
Merge branch 'develop' of https://github.com/EOEPCA/um-identity-api i…
daniel-pimenta-DME Nov 14, 2023
5931be4
Convert to FastAPI
daniel-pimenta-DME Nov 14, 2023
f4d31c5
changes to models
flaviorosadme Nov 14, 2023
025490c
Remove file
daniel-pimenta-DME Nov 14, 2023
c5a0042
Add error handling, pydantic models, files restructuring
daniel-pimenta-DME Nov 15, 2023
32303ec
Fix issues
daniel-pimenta-DME Nov 15, 2023
4c5f607
Handle keycloak error message
daniel-pimenta-DME Nov 15, 2023
fd9b791
added fildes to models and descriptions
flaviorosadme Nov 16, 2023
5030bc6
Add authenticated field
daniel-pimenta-DME Nov 16, 2023
4501347
Clean and reformat
daniel-pimenta-DME Nov 16, 2023
935e825
Point to keycloak client 1.0.0
daniel-pimenta-DME Nov 16, 2023
0389d15
Change logging
daniel-pimenta-DME Nov 16, 2023
c6c3904
Fix readme
daniel-pimenta-DME Nov 16, 2023
e92f49b
Clean
daniel-pimenta-DME Nov 16, 2023
a2fb5d8
Change logging
daniel-pimenta-DME Nov 16, 2023
774cf8f
Clean
daniel-pimenta-DME Nov 16, 2023
077df14
Merge branch 'master' of https://github.com/EOEPCA/um-identity-api in…
daniel-pimenta-DME Nov 16, 2023
4bfbaad
merge to develop
flaviorosadme Nov 16, 2023
2d89460
added default resource to response list
flaviorosadme Nov 16, 2023
6983421
Create default resource
daniel-pimenta-DME Nov 16, 2023
901ae0d
Merge branch 'develop' of https://github.com/EOEPCA/um-identity-api i…
daniel-pimenta-DME Nov 16, 2023
a863d4a
Fix policies issue
daniel-pimenta-DME Nov 17, 2023
6ebcea7
Improvements
daniel-pimenta-DME Nov 17, 2023
286ac93
Change keycloak client to v1.0.0
daniel-pimenta-DME Nov 17, 2023
6426ec8
Clarify readme
daniel-pimenta-DME Nov 17, 2023
383cf51
Merge branch 'master' into develop
daniel-pimenta-DME Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ cd um-identity-api

3. Execute

3.1 Run with docker compose
3.1 Run with docker compose (Identity API + Keycloak + Postgres)
```sh
docker compose up -d --build
```
Expand Down
107 changes: 71 additions & 36 deletions app/routers/clients_resources.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import List

from fastapi import APIRouter
from fastapi import APIRouter, HTTPException

from app.keycloak_client import keycloak
from app.log import logger
from app.models.policies import PolicyType
from app.models.resources import Resource
from app.routers.resources import get_resources

router = APIRouter(
prefix="/{client_id}/resources",
Expand All @@ -16,40 +18,73 @@
def register_resources(client_id: str, resources: List[Resource]):
response_list = []
for resource in resources:
resource_name = resource.name.replace(" ", "_")
res = {
"name": resource_name,
"uris": resource.uris,
"scopes": resource.scopes,
}
response_resource = keycloak.register_resource(res, client_id)
response_list.append(response_resource)
permissions = resource.permissions
policy_list = []
if permissions.role:
policy = {
"name": f'{resource_name}_role_policy',
"roles": [{"id": p} for p in permissions.role]
if resource.name.lower() == "default resource":
client_resources = get_resources(client_id)
default_resource = None
for client_resource in client_resources:
if client_resource["name"].lower() == "default resource":
default_resource = client_resource
if default_resource:
# update default resource
default_resource["scopes"] = resource.scopes
update_resource(client_id=client_id, resource_id=default_resource['_id'], resource=default_resource)
response_list.append(default_resource)
else:
# create default resource
res = {
"name": resource.name,
"uris": resource.uris,
"scopes": resource.scopes,
}
response_resource = keycloak.register_resource(res, client_id)
response_list.append(response_resource)
permission_payload = {
"type": "resource",
"name": f'{resource.name} Permission',
"decisionStrategy": "UNANIMOUS",
"resources": [
resource.name
],
"policies": ["Default Policy"]
}
policy_response = keycloak.register_role_policy(policy, client_id)
policy_list.append(policy_response["name"])
if permissions.user:
policy = {
"name": f'{resource_name}_user_policy',
"users": permissions.user
keycloak.create_client_authz_resource_based_permission(client_id, permission_payload)
else:
res = {
"name": resource.name,
"uris": resource.uris,
"scopes": resource.scopes,
}
policy_response = keycloak.register_user_policy(policy, client_id)
policy_list.append(policy_response["name"])
permission_payload = {
"type": "resource",
"name": f'{resource_name}_permission',
"decisionStrategy": resource.decisionStrategy,
"resources": [
resource_name
],
"policies": policy_list
}
keycloak.create_client_authz_resource_based_permission(client_id, permission_payload)
response_resource = keycloak.register_resource(res, client_id)
response_list.append(response_resource)
permissions = resource.permissions
policy_list = []
if permissions.role:
policy = {
"name": f'{resource.name} Role Policy',
"roles": [{"id": p} for p in permissions.role]
}
policy_response = keycloak.register_role_policy(policy, client_id)
print(policy_response)
policy_list.append(policy_response["name"])
if permissions.user:
policy = {
"name": f'{resource.name} User Policy',
"users": permissions.user
}
policy_response = keycloak.register_user_policy(policy, client_id)
print(policy_response)
policy_list.append(policy_response["name"])
print(policy_list)
permission_payload = {
"type": "resource",
"name": f'{resource.name} Permission',
"decisionStrategy": resource.decisionStrategy,
"resources": [
resource.name
],
"policies": policy_list
}
keycloak.create_client_authz_resource_based_permission(client_id, permission_payload)
return response_list


Expand All @@ -59,17 +94,17 @@ def delete_resource_and_policies(client_id: str, resource_name: str):
client_policies = keycloak.get_client_authz_policies(client_id)
for policy in client_policies:
for policy_type in [e.value for e in PolicyType]:
if policy['name'] == f'{resource_name}_{policy_type}_policy':
if policy['name'].lower() == f'{resource_name} {policy_type} policy'.lower():
keycloak.delete_policy(policy['id'], client_id)
# delete permissions
permissions = keycloak.get_client_resource_permissions(client_id)
for permission in permissions:
if permission['name'] == f'{resource_name}_permission':
if permission['name'].lower() == f'{resource_name} permission'.lower():
keycloak.delete_resource_permissions(client_id, permission['id'])
# delete resources
resources = keycloak.get_resources(client_id)
for resource in resources:
if resource['name'] == resource_name:
if resource['name'].lower() == resource_name.lower():
return keycloak.delete_resource(resource['_id'], client_id)


Expand Down
4 changes: 2 additions & 2 deletions app/routers/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


@router.get("")
def get_resources():
return keycloak.get_resources()
def get_resources(client_id: str):
return keycloak.get_resources(client_id)


@router.get("/resources/{resource_id}")
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ services:
- KC_DB_PASSWORD=123456
- KC_DB_USERNAME=keycloak
- KC_DB_URL_PORT=5432
entrypoint: /opt/keycloak/bin/kc.sh start
- KC_FEATURES=account3,admin-fine-grained-authz,declarative-user-profile,recovery-codes,scripts
entrypoint: /opt/keycloak/bin/kc.sh start-dev
restart: on-failure
postgres:
image: postgres:16.0
Expand Down
Loading