Skip to content

Commit

Permalink
testing mock auth
Browse files Browse the repository at this point in the history
  • Loading branch information
zcemycl committed Nov 18, 2023
1 parent 3f9e2ae commit f3bd166
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
18 changes: 14 additions & 4 deletions src/docker/oauth2/OAuth2Config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@
"match": "user",
"claims": {
"sub": "user",
"name": "user",
"given_name": "user firstname",
"family_name": "user surname",
"preferred_username": "user",
"phone_number": "+441234",
"email": "[email protected]",
"aud": [
"user"
],
"email": "[email protected]"
]
}
},
{
"requestParam": "mock_type",
"match": "admin",
"claims": {
"sub": "admin",
"name": "admin",
"given_name": "admin firstname",
"family_name": "admin surname",
"preferred_username": "admin",
"phone_number": "+441234",
"email": "[email protected]",
"aud": [
"admin"
],
"email": "[email protected]"
]
}
}
]
Expand Down
19 changes: 13 additions & 6 deletions src/example_package/auth/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests

# https://docs.aws.amazon.com/cognito/latest/developerguide/federation-endpoints.html
URL_CONF = (
"http://localhost:8002/default_issuer/.well-known/openid-configuration"
)
Expand All @@ -13,14 +14,16 @@ def get_well_known_endpoint(url: str = URL_CONF):
return resp


def get_token(url: str = URL_TOKEN):
def get_token(user: str, url: str = URL_TOKEN):
headers = {"Content-Type": "application/x-www-form-urlencoded"}
resp = requests.post(
url,
headers=headers,
data={
"grant_type": "client_credentials",
"client_id": "fake",
"client_secret": "fake",
"mock_type": "admin",
"mock_type": user,
},
)
return resp.json()
Expand All @@ -38,7 +41,11 @@ def get_jwks(url: str = URL_JWKS):

if __name__ == "__main__":
print(get_well_known_endpoint())
token_resp = get_token()
print(token_resp)
print(get_jwks())
print(get_user_info(token_resp["access_token"]))
token_resp_user = get_token("user")
token_resp_admin = get_token("admin")
print("-------Token--------\n ")
print(token_resp_user)
print(token_resp_admin)
# print(get_jwks())
print(get_user_info(token_resp_user["access_token"]))
print(get_user_info(token_resp_admin["access_token"]))

0 comments on commit f3bd166

Please sign in to comment.