feat: return username upon process_authorization_response
This commit is contained in:
parent
1ba2f16f9c
commit
4e65af9c65
|
@ -3,11 +3,12 @@ use std::sync::Arc;
|
|||
use url::Url;
|
||||
|
||||
use crate::auth::application::port::input::ui::{
|
||||
errors::*, process_authorization::ProcessAuthorizationInterface,
|
||||
errors::*,
|
||||
process_authorization::{ProcessAuthorizationInterface, ProcessAuthorizationInterfaceResp},
|
||||
};
|
||||
use crate::auth::application::port::out::db::{
|
||||
delete_oauth_state::DeleteOAuthState, oauth_state_exists::OAuthStateExists,
|
||||
save_oauth_access_token::SaveOAuthAccessToken,
|
||||
delete_oauth_access_token::DeleteOAuthAccessToken, delete_oauth_state::DeleteOAuthState,
|
||||
oauth_state_exists::OAuthStateExists, save_oauth_access_token::SaveOAuthAccessToken,
|
||||
};
|
||||
use crate::auth::application::port::out::forge::{
|
||||
get_username::GetUsername, request_access_token::RequestAccessToken,
|
||||
|
@ -21,6 +22,7 @@ pub struct ProcessAuthorizationAdapter {
|
|||
oauth_state_exists_adapter: Arc<dyn OAuthStateExists>,
|
||||
delete_oauth_state_adapter: Arc<dyn DeleteOAuthState>,
|
||||
save_oauth_access_token_adapter: Arc<dyn SaveOAuthAccessToken>,
|
||||
delete_oauth_access_token_adapter: Arc<dyn DeleteOAuthAccessToken>,
|
||||
request_access_token_adapter: Arc<dyn RequestAccessToken>,
|
||||
get_username_adapter: Arc<dyn GetUsername>,
|
||||
process_authorization_response_redirect_uri: Url,
|
||||
|
@ -31,6 +33,7 @@ impl ProcessAuthorizationAdapter {
|
|||
oauth_state_exists_adapter: Arc<dyn OAuthStateExists>,
|
||||
delete_oauth_state_adapter: Arc<dyn DeleteOAuthState>,
|
||||
save_oauth_access_token_adapter: Arc<dyn SaveOAuthAccessToken>,
|
||||
delete_oauth_access_token_adapter: Arc<dyn DeleteOAuthAccessToken>,
|
||||
request_access_token_adapter: Arc<dyn RequestAccessToken>,
|
||||
get_username_adapter: Arc<dyn GetUsername>,
|
||||
process_authorization_response_redirect_uri: Url,
|
||||
|
@ -39,6 +42,7 @@ impl ProcessAuthorizationAdapter {
|
|||
oauth_state_exists_adapter,
|
||||
delete_oauth_state_adapter,
|
||||
save_oauth_access_token_adapter,
|
||||
delete_oauth_access_token_adapter,
|
||||
request_access_token_adapter,
|
||||
get_username_adapter,
|
||||
process_authorization_response_redirect_uri,
|
||||
|
@ -55,11 +59,12 @@ impl ProcessAuthorizationInterface for ProcessAuthorizationAdapter {
|
|||
state: String,
|
||||
oauth_provider: String,
|
||||
redirect_uri: Option<Url>,
|
||||
) -> InUIResult<()> {
|
||||
) -> InUIResult<ProcessAuthorizationInterfaceResp> {
|
||||
let service = ProcessAuthorizationResponseService::new(
|
||||
self.oauth_state_exists_adapter.clone(),
|
||||
self.delete_oauth_state_adapter.clone(),
|
||||
self.save_oauth_access_token_adapter.clone(),
|
||||
self.delete_oauth_access_token_adapter.clone(),
|
||||
self.request_access_token_adapter.clone(),
|
||||
self.get_username_adapter.clone(),
|
||||
self.process_authorization_response_redirect_uri.clone(),
|
||||
|
@ -71,8 +76,8 @@ impl ProcessAuthorizationInterface for ProcessAuthorizationAdapter {
|
|||
code,
|
||||
oauth_provider,
|
||||
)?;
|
||||
service.process_authorization_response(cmd).await?;
|
||||
Ok(())
|
||||
let username = service.process_authorization_response(cmd).await?;
|
||||
Ok(ProcessAuthorizationInterfaceResp { username })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,8 +86,8 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::auth::application::port::out::{
|
||||
db::{
|
||||
delete_oauth_state::tests::*, oauth_state_exists::tests::*,
|
||||
save_oauth_access_token::tests::*,
|
||||
delete_oauth_access_token::tests::*, delete_oauth_state::tests::*,
|
||||
oauth_state_exists::tests::*, save_oauth_access_token::tests::*,
|
||||
},
|
||||
forge::{get_username::tests::*, request_access_token::tests::*},
|
||||
};
|
||||
|
@ -105,6 +110,7 @@ mod tests {
|
|||
mock_oauth_state_exists(IS_CALLED_ONLY_ONCE, RETURNS_TRUE),
|
||||
mock_delete_oauth_state(IS_CALLED_ONLY_ONCE),
|
||||
mock_save_oauth_access_token(IS_CALLED_ONLY_ONCE),
|
||||
mock_delete_oauth_access_token(IS_CALLED_ONLY_ONCE),
|
||||
mock_request_access_token(IS_CALLED_ONLY_ONCE),
|
||||
mock_get_username(username.into(), IS_CALLED_ONLY_ONCE),
|
||||
url.clone(),
|
||||
|
@ -122,6 +128,7 @@ mod tests {
|
|||
mock_oauth_state_exists(IS_CALLED_ONLY_ONCE, RETURNS_TRUE),
|
||||
mock_delete_oauth_state(IS_CALLED_ONLY_ONCE),
|
||||
mock_save_oauth_access_token(IS_CALLED_ONLY_ONCE),
|
||||
mock_delete_oauth_access_token(IS_CALLED_ONLY_ONCE),
|
||||
mock_request_access_token(IS_CALLED_ONLY_ONCE),
|
||||
mock_get_username(username.into(), IS_CALLED_ONLY_ONCE),
|
||||
url.clone(),
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
|
||||
use super::errors::*;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct ProcessAuthorizationInterfaceResp {
|
||||
pub username: String,
|
||||
}
|
||||
#[async_trait::async_trait]
|
||||
pub trait ProcessAuthorizationInterface: Send + Sync {
|
||||
async fn process_authorization(
|
||||
|
@ -10,5 +15,5 @@ pub trait ProcessAuthorizationInterface: Send + Sync {
|
|||
state: String,
|
||||
oauth_provider: String,
|
||||
redirect_uri: Option<Url>,
|
||||
) -> InUIResult<()>;
|
||||
) -> InUIResult<ProcessAuthorizationInterfaceResp>;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue