async fn find_or_refresh_token(settings: Arc<Settings>, headers: &HeaderMap) -> Option<Token> {
    let maybe_token = headers
        .typed_get::<headers::Authorization<headers::authorization::Bearer>>()
        .map(|auth| auth.0.token().to_string())
        .or_else(|| {
            headers
                .typed_get::<headers::Cookie>()
                .and_then(|cookie| cookie.get(&settings.auth_cookie).map(str::to_string))
        });

    match maybe_token.and_then(|raw_token| parse_and_validate_token(settings.clone(), raw_token)) {
        Some(token) => Some(token),
        None => refresh_token(settings, headers).await,
    }
}
// Find and validate the id token in the auth cookie or in the authorization header.
// If token does not exists or has expired, try a refresh to get a new one
Find and validate the id token in the auth cookie or in the authorization header.
If token does not exists or has expired, try a refresh to get a new one
Find and validate the id token in the auth cookie or in the authorization header . If token does not exists or has expired try a refresh to get a new one
async fn find_or_refresh_token(settings: Arc<Settings>, headers: &HeaderMap) -> Option<Token> {
    let maybe_token = headers
        .typed_get::<headers::Authorization<headers::authorization::Bearer>>()
        .map(|auth| auth.0.token().to_string())
        .or_else(|| {
            headers
                .typed_get::<headers::Cookie>()
                .and_then(|cookie| cookie.get(&settings.auth_cookie).map(str::to_string))
        });
    match maybe_token.and_then(|raw_token| parse_and_validate_token(settings.clone(), raw_token)) {
        Some(token) => Some(token),
        None => refresh_token(settings, headers).await,
    }
}
async fn find_or_refresh_token ( settings : Arc < Settings > , headers : & HeaderMap ) -> Option < Token > { let maybe_token = headers . typed_get :: < headers :: Authorization < headers :: authorization :: Bearer > > ( ) . map ( | auth | auth . 0 . token ( ) . to_string ( ) ) . or_else ( | | { headers . typed_get :: < headers :: Cookie > ( ) . and_then ( | cookie | cookie . get ( & settings . auth_cookie ) . map ( str :: to_string ) ) } ) ; match maybe_token . and_then ( | raw_token | parse_and_validate_token ( settings . clone ( ) , raw_token ) ) { Some ( token ) => Some ( token ) , None => refresh_token ( settings , headers ) . await , } }
Find and validate the id token in the auth cookie or in the authorization header.
Find and validate the id token in the auth cookie or in the authorization header .
settings
Arc<Settings>
headers
&HeaderMap
settings
Arc<Settings>
headers
&HeaderMap