-
Notifications
You must be signed in to change notification settings - Fork 39
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
feat: oauth provider #549
Open
sattvikc
wants to merge
39
commits into
0.26
Choose a base branch
from
feat/oauth-provider
base: 0.26
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: oauth provider #549
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
e2f316f
fix: files for oauth2 providers
sattvikc 59109a8
fix: interface
sattvikc f577523
fix: oauth2 interfaces
sattvikc 6479bda
fix: update recipe.py
sattvikc 94fc82d
fix: login request impl
sattvikc 1fe7e51
fix: query params for put request
sattvikc 8f96467
fix: consent request
sattvikc 804121d
fix: more impl
sattvikc 22ab47b
fix: more impl
sattvikc e7fe99c
Merge branch '0.26' into feat/oauth-provider
sattvikc e776828
fix: recipe impl
sattvikc f462284
fix: recipe impl
sattvikc c83ef6f
fix: validate_oauth2_access_token
sattvikc 2f7e994
fix: authorization
sattvikc 00a6128
fix: token exchange
sattvikc 6f6b6e4
fix: frontend redirection url
sattvikc 07868f1
fix: revoke token
sattvikc 4386cb8
fix: end session
sattvikc 2c06ffb
fix: api stubs
sattvikc eae13cc
fix: api structures and lint fixes
sattvikc c4c8d11
fix: remaining type fixes
sattvikc a1dff9d
fix: end session
sattvikc 1e35b54
fix: api endpoints
sattvikc 79194a4
fix: remaining apis
sattvikc fbee6d6
fix: remaining impl
sattvikc 9eb33ce
fix: typing
sattvikc e3d1287
fix: type and lint
sattvikc 3041401
fix: types, exposed functions and cyclic import
sattvikc 34e96da
fix: backend sdk tests
sattvikc d8dd684
fix: default recipes and fixes for test
sattvikc fc42477
fix: tests
sattvikc 724c97b
fix: tests
sattvikc dae1204
fix: tests
sattvikc 213b9fe
fix: tests
sattvikc 92a7a0b
fix: tests
sattvikc 91926ae
fix: tests
sattvikc 632b5dd
fix: openid and cookies
sattvikc 2685c31
fix: roles and permissions for oauth2
sattvikc 0226085
fix: auth react tests
sattvikc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,3 +94,9 @@ def set_json_content(self, content: Dict[str, Any]): | |
self.set_header("Content-Length", str(len(body))) | ||
self.response.body = body | ||
self.response_sent = True | ||
|
||
def redirect(self, url: str) -> BaseResponse: | ||
if not self.response_sent: | ||
self.set_header("Location", url) | ||
self.set_status_code(302) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't this need to set |
||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. | ||
# | ||
# This software is licensed under the Apache License, Version 2.0 (the | ||
# "License") as published by the Apache Software Foundation. | ||
# | ||
# You may not use this file except in compliance with the License. You may | ||
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Callable, Union | ||
|
||
from . import exceptions as ex | ||
from . import recipe, utils | ||
|
||
exceptions = ex | ||
InputOverrideConfig = utils.InputOverrideConfig | ||
|
||
if TYPE_CHECKING: | ||
from supertokens_python.supertokens import AppInfo | ||
|
||
from ...recipe_module import RecipeModule | ||
|
||
|
||
def init( | ||
override: Union[InputOverrideConfig, None] = None, | ||
) -> Callable[[AppInfo], RecipeModule]: | ||
return recipe.OAuth2ProviderRecipe.init(override) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. | ||
# | ||
# This software is licensed under the Apache License, Version 2.0 (the | ||
# "License") as published by the Apache Software Foundation. | ||
# | ||
# You may not use this file except in compliance with the License. You may | ||
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from .auth import auth_get # type: ignore | ||
from .end_session import end_session_get, end_session_post # type: ignore | ||
from .introspect_token import introspect_token_post # type: ignore | ||
from .login_info import login_info_get # type: ignore | ||
from .login import login # type: ignore | ||
from .logout import logout_post # type: ignore | ||
from .revoke_token import revoke_token_post # type: ignore | ||
from .token import token_post # type: ignore | ||
from .user_info import user_info_get # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. | ||
# | ||
# This software is licensed under the Apache License, Version 2.0 (the | ||
# "License") as published by the Apache Software Foundation. | ||
# | ||
# You may not use this file except in compliance with the License. You may | ||
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from __future__ import annotations | ||
|
||
from http.cookies import SimpleCookie | ||
from typing import TYPE_CHECKING, Any, Dict | ||
from urllib.parse import parse_qsl | ||
from dateutil import parser | ||
|
||
from supertokens_python.recipe.session.asyncio import get_session | ||
from supertokens_python.recipe.session.exceptions import TryRefreshTokenError | ||
from supertokens_python.utils import send_200_response, send_non_200_response | ||
|
||
if TYPE_CHECKING: | ||
from ..interfaces import ( | ||
APIOptions, | ||
APIInterface, | ||
) | ||
|
||
|
||
async def auth_get( | ||
_tenant_id: str, | ||
api_implementation: APIInterface, | ||
api_options: APIOptions, | ||
user_context: Dict[str, Any], | ||
): | ||
from ..interfaces import ( | ||
RedirectResponse, | ||
ErrorOAuth2Response, | ||
) | ||
|
||
if api_implementation.disable_auth_get is True: | ||
return None | ||
|
||
original_url = api_options.request.get_original_url() | ||
split_url = original_url.split("?", 1) | ||
params = dict(parse_qsl(split_url[1], True)) if len(split_url) > 1 else {} | ||
|
||
session = None | ||
should_try_refresh = False | ||
try: | ||
session = await get_session( | ||
api_options.request, | ||
session_required=False, | ||
user_context=user_context, | ||
) | ||
should_try_refresh = False | ||
except Exception as error: | ||
session = None | ||
|
||
# should_try_refresh = False should generally not happen, but we can handle this as if the session is not present, | ||
# because then we redirect to the frontend, which should handle the validation error | ||
should_try_refresh = isinstance(error, TryRefreshTokenError) | ||
|
||
response = await api_implementation.auth_get( | ||
params=params, | ||
cookie=api_options.request.get_header("cookie"), | ||
session=session, | ||
should_try_refresh=should_try_refresh, | ||
options=api_options, | ||
user_context=user_context, | ||
) | ||
|
||
if isinstance(response, RedirectResponse): | ||
if response.cookies: | ||
for cookie_string in response.cookies: | ||
cookie = SimpleCookie() | ||
cookie.load(cookie_string) | ||
for morsel in cookie.values(): | ||
api_options.response.set_cookie( | ||
key=morsel.key, | ||
value=morsel.value, | ||
domain=morsel.get("domain"), | ||
secure=morsel.get("secure", True), | ||
httponly=morsel.get("httponly", True), | ||
expires=parser.parse(morsel.get("expires", "")).timestamp() * 1000, # type: ignore | ||
path=morsel.get("path", "/"), | ||
samesite=morsel.get("samesite", "lax"), | ||
) | ||
return api_options.response.redirect(response.redirect_to) | ||
elif isinstance(response, ErrorOAuth2Response): | ||
return send_non_200_response( | ||
{ | ||
"error": response.error, | ||
"error_description": response.error_description, | ||
}, | ||
response.status_code or 400, | ||
api_options.response, | ||
) | ||
else: | ||
return send_200_response(response.to_json(), api_options.response) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this need to set
response_sent
?