1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

JWT response wrapper

Helps replying with a JWT to a request, with a
`Content-Type: application/jwt` header
This commit is contained in:
Quentin Gliech
2022-09-01 17:47:12 +02:00
parent 6818316a11
commit 1f0e273ac3
5 changed files with 45 additions and 7 deletions

View File

@@ -16,17 +16,15 @@ use anyhow::Context;
use axum::{
extract::Extension,
response::{IntoResponse, Response},
Json, TypedHeader,
Json,
};
use headers::ContentType;
use mas_axum_utils::{user_authorization::UserAuthorization, FancyError};
use mas_axum_utils::{jwt::JwtResponse, user_authorization::UserAuthorization, FancyError};
use mas_jose::{
constraints::Constrainable,
jwt::{JsonWebSignatureHeader, Jwt},
};
use mas_keystore::Keystore;
use mas_router::UrlBuilder;
use mime::Mime;
use oauth2_types::scope;
use serde::Serialize;
use serde_with::skip_serializing_none;
@@ -91,9 +89,7 @@ pub async fn get(
};
let token = Jwt::sign(header, user_info, &signer)?;
let application_jwt: Mime = "application/jwt".parse().unwrap();
let content_type = ContentType::from(application_jwt);
Ok((TypedHeader(content_type), token.as_str().to_owned()).into_response())
Ok(JwtResponse(token).into_response())
} else {
Ok(Json(user_info).into_response())
}