You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-21 23:00:50 +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}")]
|
#[error("could not decoded response content-type: {0}")]
|
||||||
DecodeResponseContentType(#[from] ToStrError),
|
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.
|
/// The content-type is not the one that was expected.
|
||||||
#[error("invalid response content-type {got:?}, expected {expected:?}")]
|
#[error("unexpected response content-type {got:?}, expected {expected:?}")]
|
||||||
InvalidResponseContentType {
|
UnexpectedResponseContentType {
|
||||||
/// The expected content-type.
|
/// The expected content-type.
|
||||||
expected: String,
|
expected: String,
|
||||||
/// The returned content-type.
|
/// The returned content-type.
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ use headers::{Authorization, HeaderMapExt, HeaderValue};
|
|||||||
use http::header::{ACCEPT, CONTENT_TYPE};
|
use http::header::{ACCEPT, CONTENT_TYPE};
|
||||||
use mas_http::CatchHttpCodesLayer;
|
use mas_http::CatchHttpCodesLayer;
|
||||||
use mas_jose::claims;
|
use mas_jose::claims;
|
||||||
|
use mime::Mime;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tower::{Layer, Service, ServiceExt};
|
use tower::{Layer, Service, ServiceExt};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@@ -98,16 +99,17 @@ pub async fn fetch_userinfo(
|
|||||||
.call(userinfo_request)
|
.call(userinfo_request)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let content_type = userinfo_response
|
let content_type: Mime = userinfo_response
|
||||||
.headers()
|
.headers()
|
||||||
.get(CONTENT_TYPE)
|
.get(CONTENT_TYPE)
|
||||||
.ok_or(UserInfoError::MissingResponseContentType)?
|
.ok_or(UserInfoError::MissingResponseContentType)?
|
||||||
.to_str()?;
|
.to_str()?
|
||||||
|
.parse()?;
|
||||||
|
|
||||||
if content_type != expected_content_type {
|
if content_type.essence_str() != expected_content_type {
|
||||||
return Err(UserInfoError::InvalidResponseContentType {
|
return Err(UserInfoError::UnexpectedResponseContentType {
|
||||||
expected: expected_content_type.to_owned(),
|
expected: expected_content_type.to_owned(),
|
||||||
got: content_type.to_owned(),
|
got: content_type.to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user