-
Notifications
You must be signed in to change notification settings - Fork 680
Append offline_access to authorization scope when AS advertises it (SEP-2207)
#1479
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -492,6 +492,7 @@ private Uri BuildAuthorizationUrl( | |||||
| } | ||||||
|
|
||||||
| var scope = GetScopeParameter(protectedResourceMetadata); | ||||||
| scope = AugmentScopeWithOfflineAccess(scope, authServerMetadata); | ||||||
| if (!string.IsNullOrEmpty(scope)) | ||||||
| { | ||||||
| queryParamsDictionary["scope"] = scope!; | ||||||
|
|
@@ -726,6 +727,37 @@ private async Task PerformDynamicClientRegistrationAsync( | |||||
| return _configuredScopes; | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Augments the scope parameter with <c>offline_access</c> if the authorization server advertises it in | ||||||
| /// <c>scopes_supported</c> and it is not already present. This signals to OIDC-flavored authorization servers | ||||||
| /// that the client desires a refresh token, per SEP-2207. | ||||||
| /// </summary> | ||||||
| private static string? AugmentScopeWithOfflineAccess(string? scope, AuthorizationServerMetadata authServerMetadata) | ||||||
| { | ||||||
| const string offlineAccess = "offline_access"; | ||||||
|
|
||||||
| if (authServerMetadata.ScopesSupported is null || !authServerMetadata.ScopesSupported.Contains(offlineAccess)) | ||||||
|
Contributor
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.
Suggested change
Contributor
Author
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. Applied in 6a23554. |
||||||
| { | ||||||
| return scope; | ||||||
|
Contributor
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. Is this correct if scope is null?
Contributor
Author
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. Yes — when the AS doesn't advertise |
||||||
| } | ||||||
|
|
||||||
| if (scope is null) | ||||||
| { | ||||||
| return offlineAccess; | ||||||
| } | ||||||
|
|
||||||
| // Check if offline_access is already in the scope string (space-separated tokens). | ||||||
| foreach (var token in scope.Split(' ')) | ||||||
| { | ||||||
| if (token == offlineAccess) | ||||||
| { | ||||||
| return scope; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return scope + " " + offlineAccess; | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Verifies that the resource URI in the metadata exactly matches the original request URL as required by the RFC. | ||||||
| /// Per RFC: The resource value must be identical to the URL that the client used to make the request to the resource server. | ||||||
|
|
||||||
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.
consts should be PascalCased
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.
Fixed in 6a23554 — renamed to
OfflineAccess.