From fa0dec737bd2988e00f8d7d742bc56d60d6e8fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Thu, 30 May 2024 10:02:55 +0200 Subject: [PATCH] Use headers API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- crates/oidc-client/src/error.rs | 4 ++-- crates/oidc-client/src/requests/userinfo.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/oidc-client/src/error.rs b/crates/oidc-client/src/error.rs index cb667c6e..8264f188 100644 --- a/crates/oidc-client/src/error.rs +++ b/crates/oidc-client/src/error.rs @@ -452,8 +452,8 @@ pub enum UserInfoError { DecodeResponseContentType(#[from] ToStrError), /// The content-type is not valid. - #[error("invalid response content-type: {0}")] - InvalidResponseContentTypeValue(#[from] mime::FromStrError), + #[error("invalid response content-type")] + InvalidResponseContentTypeValue, /// The content-type is not the one that was expected. #[error("unexpected response content-type {got:?}, expected {expected:?}")] diff --git a/crates/oidc-client/src/requests/userinfo.rs b/crates/oidc-client/src/requests/userinfo.rs index 89a7698b..2b6dc5fe 100644 --- a/crates/oidc-client/src/requests/userinfo.rs +++ b/crates/oidc-client/src/requests/userinfo.rs @@ -19,8 +19,8 @@ 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; @@ -101,10 +101,10 @@ pub async fn fetch_userinfo( let content_type: Mime = userinfo_response .headers() - .get(CONTENT_TYPE) + .typed_try_get::() + .map_err(|_| UserInfoError::InvalidResponseContentTypeValue)? .ok_or(UserInfoError::MissingResponseContentType)? - .to_str()? - .parse()?; + .into(); if content_type.essence_str() != expected_content_type { return Err(UserInfoError::UnexpectedResponseContentType {