use alcoholic_jwt::{JWKS, ValidJWT};
use tonic::metadata::MetadataMap;
use tonic::Status;
use crate::security::validator::validate_token;
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()))
}