-
Notifications
You must be signed in to change notification settings - Fork 595
Add option to enable redirect-based OAuth flow #1835
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
Open
thepatrickchin
wants to merge
13
commits into
NVIDIA:develop
Choose a base branch
from
thepatrickchin:feat/redirect-auth
base: develop
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
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1eb4718
feat: add option to open OAuth login on same tab
thepatrickchin 248b47c
feat: validate return URL origin against CORS allowlist
thepatrickchin f71727f
fix: escape return_url JSON for HTML script context
thepatrickchin 576d555
fix: display auth cancellation message when user clicks back
thepatrickchin 4a22749
fix: patch example OAuth server to support permission decline
thepatrickchin a448a56
feat: support denied consent flow
thepatrickchin ef3fc66
feat: display cancellation reason and update tests
thepatrickchin 8356430
docs: add description of use_popup_auth option
thepatrickchin 33db54c
chore: rename occurrences of "same-page" to "redirect"
thepatrickchin d1d8481
refactor: rename use_popup_auth to use_redirect_auth and negate logic
thepatrickchin ce7ec06
fix: implement CodeRabbit suggestions
thepatrickchin c792ba3
fix: implement CodeRabbit suggestions
thepatrickchin 1d8b5e9
fix: implement CodeRabbit suggestions
thepatrickchin 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
examples/front_ends/simple_auth/patches/oauth2-server.patch
This file contains hidden or 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,30 @@ | ||
| --- a/website/routes.py | ||
| +++ b/website/routes.py | ||
| @@ -105,7 +105,7 @@ | ||
| if not user and "username" in request.form: | ||
| username = request.form.get("username") | ||
| user = User.query.filter_by(username=username).first() | ||
| - if request.form["confirm"]: | ||
| + if request.form.get("confirm") == "yes": | ||
| grant_user = user | ||
| else: | ||
| grant_user = None | ||
| --- a/website/templates/authorize.html | ||
| +++ b/website/templates/authorize.html | ||
| @@ -9,14 +9,11 @@ | ||
| <form action="" method="post"> | ||
| - <label> | ||
| - <input type="checkbox" name="confirm"> | ||
| - <span>Consent?</span> | ||
| - </label> | ||
| {% if not user %} | ||
| <p>You haven't logged in. Log in with:</p> | ||
| <div> | ||
| <input type="text" name="username"> | ||
| </div> | ||
| {% endif %} | ||
| <br> | ||
| - <button>Submit</button> | ||
| + <button type="submit" name="confirm" value="yes">Authorize</button> | ||
| + <button type="submit" name="confirm" value="no">Cancel</button> | ||
| </form> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
76 changes: 76 additions & 0 deletions
76
...ges/nvidia_nat_core/src/nat/front_ends/fastapi/html_snippets/auth_code_grant_cancelled.py
This file contains hidden or 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,76 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # 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. | ||
|
|
||
| import json | ||
|
|
||
| AUTH_REDIRECT_CANCELLED_POPUP_HTML = """ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Authorization Cancelled</title> | ||
| <script> | ||
| (function () { | ||
| window.history.replaceState(null, "", window.location.pathname); | ||
|
|
||
| window.opener?.postMessage({ type: 'AUTH_CANCELLED' }, '*'); | ||
|
|
||
| window.close(); | ||
| })(); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <p>Authorization cancelled. You may now close this window.</p> | ||
| </body> | ||
| </html> | ||
| """ | ||
|
|
||
| _AUTH_REDIRECT_CANCELLED_HTML_TEMPLATE = """\ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Authorization Cancelled</title> | ||
| <script> | ||
| (function () { | ||
| var returnTo = RETURN_URL_PLACEHOLDER; | ||
| if (returnTo) { | ||
| window.location.replace(returnTo); | ||
| } else { | ||
| window.history.back(); | ||
| } | ||
| })(); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <p>Authorization cancelled. Redirecting…</p> | ||
| </body> | ||
| </html> | ||
| """ | ||
|
|
||
|
|
||
| def build_auth_redirect_cancelled_html(return_url: str | None = None) -> str: | ||
| """Build the authorization-cancelled HTML page. | ||
|
|
||
| Redirects back to the UI without the ``oauth_auth_completed`` query | ||
| parameter so the UI's cancellation-message branch handles it. | ||
|
|
||
| Args: | ||
| return_url: The UI origin to navigate back to. Falls back to | ||
| ``window.history.back()`` when not provided. | ||
|
|
||
| Returns: | ||
| An HTML string for the post-cancellation redirect page. | ||
| """ | ||
| safe_json = json.dumps(return_url).replace('<', '\\u003c').replace('>', '\\u003e').replace('/', '\\u002f') | ||
| return _AUTH_REDIRECT_CANCELLED_HTML_TEMPLATE.replace("RETURN_URL_PLACEHOLDER", safe_json) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.