Redirect user for authentication
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
use crate::actors::providers_states_actor::ProviderLoginState;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::constants::OIDC_PROVIDERS_LIFETIME;
|
||||
use crate::constants::{OIDC_PROVIDERS_LIFETIME, OIDC_PROVIDER_CB_URI};
|
||||
use crate::data::app_config::AppConfig;
|
||||
use crate::data::jwt_signer::JsonWebKey;
|
||||
use crate::data::provider::Provider;
|
||||
use crate::utils::err::Res;
|
||||
@@ -30,6 +32,18 @@ pub struct ProviderConfiguration {
|
||||
pub expire: u64,
|
||||
}
|
||||
|
||||
impl ProviderConfiguration {
|
||||
/// Get the URL where a user should be redirected to authenticate
|
||||
pub fn auth_url(&self, provider: &Provider, state: &ProviderLoginState) -> String {
|
||||
let authorization_url = &self.discovery.authorization_endpoint;
|
||||
let client_id = urlencoding::encode(&provider.client_id).to_string();
|
||||
let state = urlencoding::encode(&state.state_id).to_string();
|
||||
let callback_url = AppConfig::get().full_url(OIDC_PROVIDER_CB_URI);
|
||||
|
||||
format!("{authorization_url}?response_type=code&scope=openid%20profile%20email&client_id={client_id}&state={state}&redirect_uri={callback_url}")
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static THREAD_CACHE: RefCell<HashMap<String, ProviderConfiguration>> = RefCell::new(Default::default());
|
||||
}
|
||||
|
Reference in New Issue
Block a user