fix(auth): url parse is not correct (#402)
The format method is not good for url.
This commit is contained in:
parent
6853143684
commit
048f1ac3af
1 changed files with 16 additions and 7 deletions
|
|
@ -16,6 +16,8 @@ use thiserror::Error;
|
||||||
use tokio::sync::{Mutex, RwLock};
|
use tokio::sync::{Mutex, RwLock};
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
|
const DEFAULT_EXCHANGE_URL: &str = "http://localhost";
|
||||||
|
|
||||||
/// sse client with oauth2 authorization
|
/// sse client with oauth2 authorization
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AuthClient<C> {
|
pub struct AuthClient<C> {
|
||||||
|
|
@ -225,10 +227,17 @@ impl AuthorizationManager {
|
||||||
// discard the path part, only keep scheme, host, port
|
// discard the path part, only keep scheme, host, port
|
||||||
auth_base.set_path("");
|
auth_base.set_path("");
|
||||||
|
|
||||||
|
// Helper function to create endpoint URL
|
||||||
|
let create_endpoint = |path: &str| -> String {
|
||||||
|
let mut url = auth_base.clone();
|
||||||
|
url.set_path(path);
|
||||||
|
url.to_string()
|
||||||
|
};
|
||||||
|
|
||||||
Ok(AuthorizationMetadata {
|
Ok(AuthorizationMetadata {
|
||||||
authorization_endpoint: format!("{}/authorize", auth_base),
|
authorization_endpoint: create_endpoint("authorize"),
|
||||||
token_endpoint: format!("{}/token", auth_base),
|
token_endpoint: create_endpoint("token"),
|
||||||
registration_endpoint: format!("{}/register", auth_base),
|
registration_endpoint: create_endpoint("register"),
|
||||||
issuer: None,
|
issuer: None,
|
||||||
jwks_uri: None,
|
jwks_uri: None,
|
||||||
scopes_supported: None,
|
scopes_supported: None,
|
||||||
|
|
@ -686,7 +695,7 @@ impl OAuthState {
|
||||||
if let OAuthState::Unauthorized(manager) = self {
|
if let OAuthState::Unauthorized(manager) = self {
|
||||||
let mut manager = std::mem::replace(
|
let mut manager = std::mem::replace(
|
||||||
manager,
|
manager,
|
||||||
AuthorizationManager::new("http://localhost").await?,
|
AuthorizationManager::new(DEFAULT_EXCHANGE_URL).await?,
|
||||||
);
|
);
|
||||||
|
|
||||||
// write credentials
|
// write credentials
|
||||||
|
|
@ -716,7 +725,7 @@ impl OAuthState {
|
||||||
) -> Result<(), AuthError> {
|
) -> Result<(), AuthError> {
|
||||||
if let OAuthState::Unauthorized(mut manager) = std::mem::replace(
|
if let OAuthState::Unauthorized(mut manager) = std::mem::replace(
|
||||||
self,
|
self,
|
||||||
OAuthState::Unauthorized(AuthorizationManager::new("http://localhost").await?),
|
OAuthState::Unauthorized(AuthorizationManager::new(DEFAULT_EXCHANGE_URL).await?),
|
||||||
) {
|
) {
|
||||||
debug!("start discovery");
|
debug!("start discovery");
|
||||||
let metadata = manager.discover_metadata().await?;
|
let metadata = manager.discover_metadata().await?;
|
||||||
|
|
@ -736,7 +745,7 @@ impl OAuthState {
|
||||||
pub async fn complete_authorization(&mut self) -> Result<(), AuthError> {
|
pub async fn complete_authorization(&mut self) -> Result<(), AuthError> {
|
||||||
if let OAuthState::Session(session) = std::mem::replace(
|
if let OAuthState::Session(session) = std::mem::replace(
|
||||||
self,
|
self,
|
||||||
OAuthState::Unauthorized(AuthorizationManager::new("http://localhost").await?),
|
OAuthState::Unauthorized(AuthorizationManager::new(DEFAULT_EXCHANGE_URL).await?),
|
||||||
) {
|
) {
|
||||||
*self = OAuthState::Authorized(session.auth_manager);
|
*self = OAuthState::Authorized(session.auth_manager);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -748,7 +757,7 @@ impl OAuthState {
|
||||||
pub async fn to_authorized_http_client(&mut self) -> Result<(), AuthError> {
|
pub async fn to_authorized_http_client(&mut self) -> Result<(), AuthError> {
|
||||||
if let OAuthState::Authorized(manager) = std::mem::replace(
|
if let OAuthState::Authorized(manager) = std::mem::replace(
|
||||||
self,
|
self,
|
||||||
OAuthState::Authorized(AuthorizationManager::new("http://localhost").await?),
|
OAuthState::Authorized(AuthorizationManager::new(DEFAULT_EXCHANGE_URL).await?),
|
||||||
) {
|
) {
|
||||||
*self = OAuthState::AuthorizedHttpClient(AuthorizedHttpClient::new(
|
*self = OAuthState::AuthorizedHttpClient(AuthorizedHttpClient::new(
|
||||||
Arc::new(manager),
|
Arc::new(manager),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue