Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zcemycl committed Nov 20, 2023
1 parent 574dec8 commit 0ea79c0
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 36 deletions.
25 changes: 25 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

from .database import get_async_session

# import requests


app = FastAPI()


Expand Down Expand Up @@ -46,3 +49,25 @@ async def get_async_skills(
res = (await session.execute(stmt)).mappings().all()
logger.info(res)
return res


# @app.get("/login_page")
# async def login_page():
# headers = {"Content-Type": "application/x-www-form-urlencoded"}
# data = {
# "grant_type":"client_credentials",
# "client_id":"fake",
# "client_secret":"fake",
# "mock_type":"user",
# }
# # if grant_type == "refresh_token":
# # data["refresh_token"] = refresh_token
# resp = requests.post(
# "http://oauth:8080/default_issuer/token",
# headers=headers,
# data=data,
# )
# return {
# **resp.json(),
# "id_token": "7cZPgOvv?hMc6j8FqMuYhx=g45454gw?vOWZM?!vz2FB7dAf?O?63iY"
# }
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pydantic-settings
python-jose
PyJWT
bcrypt
requests
1 change: 1 addition & 0 deletions src/docker/oauth2/OAuth2Config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"interactiveLogin": false,
"loginPagePath": "/conf/login.example.html",
"httpServer": "NettyWrapper",
"tokenCallbacks": [
{
Expand Down
39 changes: 39 additions & 0 deletions src/docker/oauth2/login.example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Mock OAuth2 Server Example Sign-in</title>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>

<body>
<div class="container">
<div class="row mt-5 justify-content-md-center">
<div class="col-md-5">
<form method="post">
<div></div>
<h4><img src="/static/nav-logo-red.svg" />&nbsp;&nbsp; Mock OAuth2 Server Example</h4>
<hr class="divisor">
<div class="form-group">
<input type="text" class="form-control" name="username" autofocus="on"
placeholder="Enter any user/subject">
</div>
<div class="form-group">
<textarea class="form-control" name="claims" rows="15" placeholder="Optional claims JSON value, example:
{
&quot;acr&quot;: &quot;reference&quot;
}"
></textarea>
</div>
<button type="submit" class="btn btn-primary topBtn"><i class="fa fa-sign-in"></i>Sign-in</button>
</form>
</div>
</div>
</div>
</body>

</html>
91 changes: 55 additions & 36 deletions src/example_package/auth/third_party_jwt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,40 +107,59 @@ def end_session(url: str = URL_END):


if __name__ == "__main__":
print(get_well_known_endpoint())
token_resp_user = get_token(
grant_type="client_credentials",
client_id="fake",
client_secret="fake",
user="user",
)
token_resp_admin = get_token(
grant_type="client_credentials",
client_id="fake",
client_secret="fake",
user="admin",
)
print("-------Token--------\n ")
print(token_resp_user)
print(token_resp_admin)
print(get_user_info(token_resp_user["access_token"]))
print(get_user_info(token_resp_admin["access_token"]))

new_token_resp_user = get_token(
grant_type="refresh_token",
client_id="fake",
client_secret="fake",
refresh_token=token_resp_user["access_token"],
user="user",
# print(get_well_known_endpoint())
# token_resp_user = get_token(
# grant_type="client_credentials",
# client_id="fake",
# client_secret="fake",
# user="user",
# )
# token_resp_admin = get_token(
# grant_type="client_credentials",
# client_id="fake",
# client_secret="fake",
# user="admin",
# )
# print("-------Token--------\n ")
# print(token_resp_user)
# print(token_resp_admin)
# print(get_user_info(token_resp_user["access_token"]))
# print(get_user_info(token_resp_admin["access_token"]))

# new_token_resp_user = get_token(
# grant_type="refresh_token",
# client_id="fake",
# client_secret="fake",
# refresh_token=token_resp_user["access_token"],
# user="user",
# )
# print(get_user_info(new_token_resp_user["access_token"]))

# print("------- jwks -------\n")
# print(get_jwks())
# introspect(new_token_resp_user["access_token"])
# revoke_token(new_token_resp_user["access_token"])
# introspect(new_token_resp_user["access_token"])

# end_session()
# introspect(new_token_resp_user["access_token"])
# introspect(token_resp_admin["access_token"])

# https://identityserver4.readthedocs.io/en/latest/endpoints/authorize.html#
auth_resp = requests.get(
"http://localhost:8002/default_issuer/authorize",
params={
"client_id": "fake",
# "response_type": "id_token token",
# "scope": "openid profile",
"response_type": "code",
"scope": "openid",
"redirect_uri": "http://localhost:4555/login_page",
"state": "abc",
"nonce": "abc",
# "code": "1234"
},
data={"username": "user"},
)
print(get_user_info(new_token_resp_user["access_token"]))

print("------- jwks -------\n")
print(get_jwks())
introspect(new_token_resp_user["access_token"])
revoke_token(new_token_resp_user["access_token"])
introspect(new_token_resp_user["access_token"])

end_session()
introspect(new_token_resp_user["access_token"])
introspect(token_resp_admin["access_token"])
print(auth_resp.text)
print(auth_resp.json())

0 comments on commit 0ea79c0

Please sign in to comment.