You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-20 12:02:22 +03:00
Allow parameters in UserInfo endpoint's response's content-type
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
committed by
Quentin Gliech
parent
206d45bb31
commit
683516bb66
@@ -451,9 +451,13 @@ pub enum UserInfoError {
|
||||
#[error("could not decoded response content-type: {0}")]
|
||||
DecodeResponseContentType(#[from] ToStrError),
|
||||
|
||||
/// The content-type is not valid.
|
||||
#[error("invalid response content-type: {0}")]
|
||||
InvalidResponseContentTypeValue(#[from] mime::FromStrError),
|
||||
|
||||
/// The content-type is not the one that was expected.
|
||||
#[error("invalid response content-type {got:?}, expected {expected:?}")]
|
||||
InvalidResponseContentType {
|
||||
#[error("unexpected response content-type {got:?}, expected {expected:?}")]
|
||||
UnexpectedResponseContentType {
|
||||
/// The expected content-type.
|
||||
expected: String,
|
||||
/// The returned content-type.
|
||||
|
||||
@@ -23,6 +23,7 @@ use headers::{Authorization, HeaderMapExt, HeaderValue};
|
||||
use http::header::{ACCEPT, CONTENT_TYPE};
|
||||
use mas_http::CatchHttpCodesLayer;
|
||||
use mas_jose::claims;
|
||||
use mime::Mime;
|
||||
use serde_json::Value;
|
||||
use tower::{Layer, Service, ServiceExt};
|
||||
use url::Url;
|
||||
@@ -98,16 +99,17 @@ pub async fn fetch_userinfo(
|
||||
.call(userinfo_request)
|
||||
.await?;
|
||||
|
||||
let content_type = userinfo_response
|
||||
let content_type: Mime = userinfo_response
|
||||
.headers()
|
||||
.get(CONTENT_TYPE)
|
||||
.ok_or(UserInfoError::MissingResponseContentType)?
|
||||
.to_str()?;
|
||||
.to_str()?
|
||||
.parse()?;
|
||||
|
||||
if content_type != expected_content_type {
|
||||
return Err(UserInfoError::InvalidResponseContentType {
|
||||
if content_type.essence_str() != expected_content_type {
|
||||
return Err(UserInfoError::UnexpectedResponseContentType {
|
||||
expected: expected_content_type.to_owned(),
|
||||
got: content_type.to_owned(),
|
||||
got: content_type.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user