Request offline_access scope when supported (SEP-2207)#365
Merged
koic merged 1 commit intoMay 31, 2026
Merged
Conversation
0ae44e8 to
3d22e05
Compare
## Motivation and Context SEP-2207 describes how an OAuth client obtains refresh tokens: it declares the `refresh_token` grant type in its client metadata and requests the `offline_access` scope, but only when the authorization server advertises `offline_access` in its metadata `scopes_supported`. Requesting `offline_access` when the server does not list it is forbidden. The Ruby SDK already supports the refresh grant (`Flow#refresh!`) but never requested `offline_access`, so it could not obtain a refresh token from a server that gates it behind that scope. This aligns the SDK with the Python and TypeScript SDKs and makes the `auth/offline-access-scope` conformance scenario pass (previously it reported one warning, `sep-2207-client-metadata-grant-types`, and was listed in the expected-failures baseline). The change adds: - `Flow#augment_scope_with_offline_access`, called from `run!` after `resolve_scope`, appends `offline_access` to the requested scope when both the client opted into refresh tokens (its registered `grant_types` include `refresh_token`) and the authorization server advertises `offline_access` in its metadata `scopes_supported`. Already-present `offline_access` is not duplicated. Gating on the server advertisement keeps the SDK from ever requesting the scope where it is not supported. - `conformance/client.rb` declares `refresh_token` in `grant_types`, an honest reflection of the SDK's refresh support, which clears the SEP-2207 grant-types warning. - `auth/offline-access-scope` is removed from `conformance/expected_failures.yml`. ## How Has This Been Tested? New `Flow` tests cover: `offline_access` is requested when the server advertises it and the client declared the `refresh_token` grant; `offline_access` is NOT requested when the client did not declare the grant; `offline_access` is NOT requested when the server does not advertise it (even with the grant declared); and `offline_access` is not duplicated when it is already part of the resolved scope. Conformance: `auth/offline-access-scope` now passes 14/14 with no warnings, and `auth/offline-access-not-supported` still passes 13/13 (no regression). `bundle exec rake test`, `bundle exec rake rubocop`, and `bundle exec rake conformance` are all green. ## Breaking Changes None. `offline_access` is appended only when the client's own `grant_types` opt into refresh tokens and the authorization server advertises the scope, so existing clients that do neither see no change in the scope they request.
3d22e05 to
fdca6f5
Compare
atesgoral
approved these changes
May 30, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation and Context
SEP-2207 describes how an OAuth client obtains refresh tokens: it declares the
refresh_tokengrant type in its client metadata and requests theoffline_accessscope, but only when the authorization server advertisesoffline_accessin its metadatascopes_supported. Requestingoffline_accesswhen the server does not list it is forbidden.The Ruby SDK already supports the refresh grant (
Flow#refresh!) but never requestedoffline_access, so it could not obtain a refresh token from a server that gates it behind that scope. This aligns the SDK with the Python and TypeScript SDKs and makes theauth/offline-access-scopeconformance scenario pass (previously it reported one warning,sep-2207-client-metadata-grant-types, and was listed in the expected-failures baseline).The change adds:
Flow#augment_scope_with_offline_access, called fromrun!afterresolve_scope, appendsoffline_accessto the requested scope when both the client opted into refresh tokens (its registeredgrant_typesincluderefresh_token) and the authorization server advertisesoffline_accessin its metadatascopes_supported. Already-presentoffline_accessis not duplicated. Gating on the server advertisement keeps the SDK from ever requesting the scope where it is not supported.conformance/client.rbdeclaresrefresh_tokeningrant_types, an honest reflection of the SDK's refresh support, which clears the SEP-2207 grant-types warning.auth/offline-access-scopeis removed fromconformance/expected_failures.yml.How Has This Been Tested?
New
Flowtests cover:offline_accessis requested when the server advertises it and the client declared therefresh_tokengrant;offline_accessis NOT requested when the client did not declare the grant;offline_accessis NOT requested when the server does not advertise it (even with the grant declared); andoffline_accessis not duplicated when it is already part of the resolved scope.Conformance:
auth/offline-access-scopenow passes 14/14 with no warnings, andauth/offline-access-not-supportedstill passes 13/13 (no regression).bundle exec rake test,bundle exec rake rubocop, andbundle exec rake conformanceare all green.Breaking Changes
None.
offline_accessis appended only when the client's owngrant_typesopt into refresh tokens and the authorization server advertises the scope, so existing clients that do neither see no change in the scope they request.Types of changes
Checklist