oidc-util 0.0.1

OIDC utility
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use alcoholic_jwt::{JWKS, ValidJWT};
use tonic::metadata::MetadataMap;
use tonic::Status;
use crate::security::validator::validate_token;

/// Authenticates a user by extracting the authorization token from the request metadata
pub fn authenticate(metadata: &MetadataMap, jwks: &JWKS, issuer_uri: &str) -> Result<ValidJWT, Status> {
    let bearer_token = match metadata.get("authorization") {
        None => return Err(Status::unauthenticated("authorization header not provided")),
        Some(authorization) => {
            authorization.to_str()
                .map_err(|e| Status::unauthenticated(e.to_string()))?
        }
    };

    validate_token(bearer_token, jwks, issuer_uri)
        .map_err(|e1| Status::unauthenticated(e1.to_string()))
}