generated from amazon-archives/__template_Custom
-
Couldn't load subscription status.
- Fork 343
feat: add configurable OAuth redirect uri #3124
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
Merged
Merged
Changes from all commits
Commits
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,7 @@ pub struct HttpServiceBuilder<'a> { | |
| pub timeout: u64, | ||
| pub scopes: &'a [String], | ||
| pub headers: &'a HashMap<String, String>, | ||
| pub oauth_config: &'a Option<crate::cli::chat::tools::custom_tool::OAuthConfig>, | ||
|
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. nit - import |
||
| pub messenger: &'a dyn Messenger, | ||
| } | ||
|
|
||
|
|
@@ -207,6 +208,7 @@ impl<'a> HttpServiceBuilder<'a> { | |
| timeout: u64, | ||
| scopes: &'a [String], | ||
| headers: &'a HashMap<String, String>, | ||
| oauth_config: &'a Option<crate::cli::chat::tools::custom_tool::OAuthConfig>, | ||
| messenger: &'a dyn Messenger, | ||
| ) -> Self { | ||
| Self { | ||
|
|
@@ -216,6 +218,7 @@ impl<'a> HttpServiceBuilder<'a> { | |
| timeout, | ||
| scopes, | ||
| headers, | ||
| oauth_config, | ||
| messenger, | ||
| } | ||
| } | ||
|
|
@@ -231,6 +234,7 @@ impl<'a> HttpServiceBuilder<'a> { | |
| timeout, | ||
| scopes, | ||
| headers, | ||
| oauth_config, | ||
| messenger, | ||
| } = self; | ||
|
|
||
|
|
@@ -292,7 +296,9 @@ impl<'a> HttpServiceBuilder<'a> { | |
| cred_full_path.clone(), | ||
| reg_full_path.clone(), | ||
| scopes, | ||
| oauth_config, | ||
| messenger, | ||
| os, | ||
| ) | ||
| .await?; | ||
|
|
||
|
|
@@ -452,7 +458,9 @@ async fn get_auth_manager( | |
| cred_full_path: PathBuf, | ||
| reg_full_path: PathBuf, | ||
| scopes: &[String], | ||
| oauth_config: &Option<crate::cli::chat::tools::custom_tool::OAuthConfig>, | ||
| messenger: &dyn Messenger, | ||
| os: &Os, | ||
| ) -> Result<AuthorizationManager, OauthUtilError> { | ||
| let cred_as_bytes = tokio::fs::read(&cred_full_path).await; | ||
| let reg_as_bytes = tokio::fs::read(®_full_path).await; | ||
|
|
@@ -474,7 +482,7 @@ async fn get_auth_manager( | |
| _ => { | ||
| info!("Error reading cached credentials"); | ||
| debug!("## mcp: cache read failed. constructing auth manager from scratch"); | ||
| let (am, redirect_uri) = get_auth_manager_impl(oauth_state, scopes, messenger).await?; | ||
| let (am, redirect_uri) = get_auth_manager_impl(oauth_state, scopes, oauth_config, messenger, os).await?; | ||
|
|
||
| // Client registration is done in [start_authorization] | ||
| // If we have gotten past that point that means we have the info to persist the | ||
|
|
@@ -509,9 +517,21 @@ async fn get_auth_manager( | |
| async fn get_auth_manager_impl( | ||
| mut oauth_state: OAuthState, | ||
| scopes: &[String], | ||
| oauth_config: &Option<crate::cli::chat::tools::custom_tool::OAuthConfig>, | ||
| messenger: &dyn Messenger, | ||
| _os: &Os, | ||
| ) -> Result<(AuthorizationManager, String), OauthUtilError> { | ||
| let socket_addr = SocketAddr::from(([127, 0, 0, 1], 0)); | ||
| // Get port from per-server oauth config, or use 0 for random port assignment | ||
| let port = oauth_config | ||
| .as_ref() | ||
| .and_then(|cfg| cfg.redirect_uri.as_ref()) | ||
| .and_then(|uri| { | ||
| // Parse port from redirect_uri like "127.0.0.1:7778" or ":7778" | ||
| uri.split(':').last().and_then(|p| p.parse::<u16>().ok()) | ||
| }) | ||
| .unwrap_or(0); // Port 0 = OS assigns random available port | ||
|
|
||
| let socket_addr = SocketAddr::from(([127, 0, 0, 1], port)); | ||
| let cancellation_token = tokio_util::sync::CancellationToken::new(); | ||
| let (tx, rx) = tokio::sync::oneshot::channel::<(String, String)>(); | ||
|
|
||
|
|
||
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
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.
Assuming we want this to more or less match what you linked w/ gemini - https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md#oauth-configuration-properties
There's already a top-level oauth_scopes unfortunately which could've been included in here, but I think it does make sense to add any and all future OAuth related config items here going forward
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.
If i have some time this week, I can refactor oauth_scopes to be inside this config to consolidate this going forward