Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Allow parameters in UserInfo endpoint's response's content-type #2808

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/oidc-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
InvalidResponseContentTypeValue,

/// 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.
Expand Down
18 changes: 10 additions & 8 deletions crates/oidc-client/src/requests/userinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
use std::collections::HashMap;

use bytes::Bytes;
use headers::{Authorization, HeaderMapExt, HeaderValue};
use http::header::{ACCEPT, CONTENT_TYPE};
use headers::{Authorization, ContentType, HeaderMapExt, HeaderValue};
use http::header::ACCEPT;
use mas_http::CatchHttpCodesLayer;
use mas_jose::claims;
use mime::Mime;
use serde_json::Value;
use tower::{Layer, Service, ServiceExt};
use url::Url;
Expand Down Expand Up @@ -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)
.typed_try_get::<ContentType>()
.map_err(|_| UserInfoError::InvalidResponseContentTypeValue)?
.ok_or(UserInfoError::MissingResponseContentType)?
.to_str()?;
.into();

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(),
});
}

Expand Down
Loading