Something went wrong. Try again.
An OIDC provider for AT Protocol OAuth. Rust port of apenwarr/atlogin.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121use super::{AppState, response::*};
use axum::http::{HeaderName, StatusCode};use axum::response::Response;use jiff::Timestamp;
use crate::clients::{EmailPolicy, RegisteredClient};use crate::flows::{AuthorizationCode, BrowserSession, CODE_LIFETIME};use crate::identity::Identity;use crate::oidc::{AuthorizationRequest, AuthorizationTarget, EmailClaim, Scope};
pub(super) struct Authenticated { pub(super) identity: Identity, pub(super) email: Option<EmailClaim>, pub(super) auth_time: Timestamp,}
impl From<BrowserSession> for Authenticated { fn from(session: BrowserSession) -> Self { Self { identity: Identity { did: session.did, handle: session.handle, }, email: session.email, auth_time: session.auth_time, } }}
pub(super) fn issue_code_for<L>( state: &AppState<L>, client: &RegisteredClient, target: AuthorizationTarget, authenticated: Authenticated, now: Timestamp, extra_headers: Vec<(HeaderName, String)>, status: StatusCode,) -> Result<Response, HttpError> { let Authenticated { identity, email, auth_time, } = authenticated; let refuse = |description: &str, extra_headers| { error_redirect( state, status, target.redirect_uri.clone(), target.client_state.as_deref(), "access_denied", description, extra_headers, ) }; if !client.permits(&identity) { tracing::info!( client = target.client_id.as_str(), did = identity.did.as_str(), handle = identity.handle.as_str(), "authorization refused: the account is not on the client's admission list" ); return Ok(refuse( "this account is not admitted to this application", extra_headers, )); } let policy = client.email_policy(); if policy == EmailPolicy::Required && email.is_none() { tracing::info!( client = target.client_id.as_str(), did = identity.did.as_str(), "authorization refused: the client requires an email address the PDS did not supply" ); return Ok(refuse( "this application requires an email address from your PDS", extra_headers, )); } let email = email.filter(|_| policy.discloses() && target.scopes.contains(&Scope::Email)); tracing::info!( client = target.client_id.as_str(), did = identity.did.as_str(), handle = identity.handle.as_str(), remembered = auth_time != now, email = email.is_some(), "authorization code issued" ); let code = state.flows.issue_code(AuthorizationCode { client_id: target.client_id, redirect_uri: target.redirect_uri.clone(), nonce: target.nonce, challenge: target.challenge, identity, auth_time, expires_at: now + CODE_LIFETIME, email, scopes: target.scopes, })?; Ok(redirect_to( state.config.issuer(), status, target.redirect_uri, target.client_state.as_deref(), &[("code", &code)], extra_headers, ))}
pub(super) fn plaintext_form_action(request: &AuthorizationRequest) -> Option<String> { if !request.client.insecure_redirects() { return None; } let target = &request.target.redirect_uri; match target.scheme() { "https" => None, "http" => Some(target.origin().ascii_serialization()), scheme => Some(format!("{scheme}:")), }}