Query userinfo endpoint
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-26 14:37:31 +02:00
parent b26e283f7d
commit bf20e5ad13
5 changed files with 63 additions and 37 deletions

View File

@@ -8,7 +8,7 @@ use crate::actors::providers_states_actor::ProviderLoginState;
use crate::constants::OIDC_PROVIDERS_LIFETIME;
use crate::data::app_config::AppConfig;
use crate::data::jwt_signer::JsonWebKey;
use crate::data::openid_primitive::TokenResponse;
use crate::data::openid_primitive::{OpenIDUserInfo, TokenResponse};
use crate::data::provider::Provider;
use crate::utils::err::Res;
use crate::utils::time::time;
@@ -32,7 +32,7 @@ pub struct ProviderJWKs {
#[derive(Debug, Clone)]
pub struct ProviderConfiguration {
pub discovery: ProviderDiscovery,
pub keys: ProviderJWKs,
//pub keys: ProviderJWKs,
pub expire: u64,
}
@@ -72,6 +72,22 @@ impl ProviderConfiguration {
.json()
.await?)
}
/// Retrieve information about the user, using given [TokenResponse]
pub async fn get_userinfo(&self, token: &TokenResponse) -> Res<OpenIDUserInfo> {
Ok(reqwest::Client::new()
.get(
self.discovery
.userinfo_endpoint
.as_ref()
.expect("Userinfo endpoint is required by this implementation!"),
)
.header("Authorization", format!("Bearer {}", token.access_token))
.send()
.await?
.json()
.await?)
}
}
thread_local! {
@@ -108,11 +124,11 @@ impl ProviderConfigurationHelper {
.json()
.await?;
let keys: ProviderJWKs = reqwest::get(&discovery.jwks_uri).await?.json().await?;
// let keys: ProviderJWKs = reqwest::get(&discovery.jwks_uri).await?.json().await?;
Ok(ProviderConfiguration {
discovery,
keys,
// keys,
expire: time() + OIDC_PROVIDERS_LIFETIME,
})
}