Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 28, 2023
1 parent 5d34dce commit c41a15c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions plugins/auth_fief/fps_auth_fief/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ async def auth_callback(
user_id = user_info["sub"]
async with httpx.AsyncClient() as client:
headers = {"Authorization": f"Bearer {auth_fief_config.admin_api_key}"}
r = await client.get(f"{auth_fief_config.base_url}/admin/api/oauth-providers/{auth_fief_config.oauth_provider_id}/access-token/{user_id}", headers=headers)
r = await client.get(
f"{auth_fief_config.base_url}/admin/api/oauth-providers/{auth_fief_config.oauth_provider_id}/access-token/{user_id}",
headers=headers,
)

# FIXME: this is hard-coded for GitHub authentication
access_token = r.json()["access_token"]
Expand Down Expand Up @@ -70,16 +73,28 @@ async def auth_callback(
got = 0
while True:
params = {"limit": nb, "skip": skip}
r = (await client.get(f"{auth_fief_config.base_url}/admin/api/permissions/", headers=headers, params=params)).json()
r = (
await client.get(
f"{auth_fief_config.base_url}/admin/api/permissions/",
headers=headers,
params=params,
)
).json()
if count is None:
count = r["count"]

permission_id = {result["codename"]: result["id"] for result in r["results"]}
permission_id = {
result["codename"]: result["id"] for result in r["results"]
}

headers = {"Authorization": f"Bearer {auth_fief_config.admin_api_key}"}
for permission, id in permission_id.items():
data = {"id": id}
await client.post(f"{auth_fief_config.base_url}/admin/api/users/{user_id}/permissions", headers=headers, json=data)
await client.post(
f"{auth_fief_config.base_url}/admin/api/users/{user_id}/permissions",
headers=headers,
json=data,
)

got += len(r["results"])
if got < count:
Expand Down

0 comments on commit c41a15c

Please sign in to comment.