Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 626
fix(auth): add an SDK path for pre-registered OAuth clients#994
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
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -2803,6 +2803,34 @@ impl AuthorizationSession { | ||||||
| }) | ||||||
| } | ||||||
| /// create a session using pre-registered client credentials, skipping | ||||||
| /// dynamic client registration and URL-based client IDs. | ||||||
| /// | ||||||
| /// The manager must already have discovered authorization server metadata. | ||||||
| /// | ||||||
| /// On failure, the manager is returned alongside the error so callers can | ||||||
| /// retry without losing the original configuration and stores. | ||||||
| pub async fn with_preregistered_client( | ||||||
| mut auth_manager: AuthorizationManager, | ||||||
| config: OAuthClientConfig, | ||||||
| ) -> Result<Self, (AuthorizationManager, AuthError)> { | ||||||
| let redirect_uri = config.redirect_uri.clone(); | ||||||
| let scopes = config.scopes.clone(); | ||||||
| if let Err(e) = auth_manager.configure_client(config) { | ||||||
| return Err((auth_manager, e)); | ||||||
| } | ||||||
| let scope_refs: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect(); | ||||||
| let auth_url = match auth_manager.get_authorization_url(&scope_refs).await { | ||||||
| Ok(url) => url, | ||||||
| Err(e) => return Err((auth_manager, e)), | ||||||
| }; | ||||||
| Ok(Self { | ||||||
| auth_manager, | ||||||
| auth_url, | ||||||
| redirect_uri, | ||||||
| }) | ||||||
| } | ||||||
| /// create session for scope upgrade flow (existing manager + pre-computed auth url) | ||||||
| pub fn for_scope_upgrade( | ||||||
| auth_manager: AuthorizationManager, | ||||||
| @@ -3073,6 +3101,50 @@ impl OAuthState { | ||||||
| } | ||||||
| } | ||||||
| /// start authorization using pre-registered client credentials, | ||||||
| /// skipping dynamic client registration. | ||||||
| /// | ||||||
| /// Use this when the client was registered with the authorization server | ||||||
| /// out of band and already holds a `client_id` (and optionally a | ||||||
| /// `client_secret`). If `config.scopes` is empty, scopes are selected | ||||||
| /// using the SDK's normal scope-selection policy. | ||||||
| pub async fn start_authorization_with_preregistered_client( | ||||||
| ||||||
| #[tokio::test] | |
| asyncfncustom_http_client_handles_registration_exchange_and_refresh(){ |
DaleSeoJul 16, 2026 •
edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
The draft authorization spec recommends the priority pre-registered client information → CIMD → DCR, but the current API exposes these choices through separate entry points. In particular, start_authorization() passes no metadata URL and therefore cannot take the preferred CIMD path, while start_authorization_with_metadata_url() is the method that actually implements CIMD with DCR fallback. This PR understandably extends that pattern with another mechanism-specific method, but we might want to consolidates these paths behind one start_authorization API. This is out of scope and non-blocking for this PR. Let me know what you think, and we can follow up on this separately.
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.
That makes sense to me. Probably a good thing to do jointly along with cleaning up the API as you suggested in the above comment.
Opened: #1006
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.
@jamadeo Sounds good! Let's fast-follow on this so we can include it in v3 alongside the other breaking changes.
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.
The same impl currently exposes
newandfor_scope_upgrade. Whilewith_*is valid Rust naming, the three constructors do not seem to communicate an obvious shared convention. I was just thinking we could clean up the API, since v3 allows us to make breaking changes.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.
Yes, good point, we should take the opportunity. Probably best in a follow-up PR - what do you think? What's your preferred convention?
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.
My preference would be a single
AuthorizationSession::new(...)plus chained builder methods for the optional parts. Same shape asOAuthClientConfig.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.
Oh, I found this: https://rust-lang.github.io/api-guidelines/naming.html Just FYI