-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the id_token optional on upstream OAuth 2.0 providers
This makes it possible to use non-OIDC providers as upstream OAuth 2.0 providers, like GitHub.
- Loading branch information
Showing
5 changed files
with
82 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,24 +4,19 @@ | |
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Please see LICENSE in the repository root for full details. | ||
|
||
use assert_matches::assert_matches; | ||
use mas_oidc_client::{ | ||
error::{IdTokenError, UserInfoError}, | ||
requests::userinfo::fetch_userinfo, | ||
}; | ||
use mas_oidc_client::requests::userinfo::fetch_userinfo; | ||
use serde_json::json; | ||
use wiremock::{ | ||
matchers::{header, method, path}, | ||
Mock, ResponseTemplate, | ||
}; | ||
|
||
use crate::{id_token, init_test, ACCESS_TOKEN, SUBJECT_IDENTIFIER}; | ||
use crate::{init_test, ACCESS_TOKEN, SUBJECT_IDENTIFIER}; | ||
|
||
#[tokio::test] | ||
async fn pass_fetch_userinfo() { | ||
let (http_client, mock_server, issuer) = init_test().await; | ||
let userinfo_endpoint = issuer.join("userinfo").unwrap(); | ||
let (auth_id_token, _) = id_token(issuer.as_str()); | ||
|
||
Mock::given(method("GET")) | ||
.and(path("/userinfo")) | ||
|
@@ -36,50 +31,9 @@ async fn pass_fetch_userinfo() { | |
.mount(&mock_server) | ||
.await; | ||
|
||
let claims = fetch_userinfo( | ||
&http_client, | ||
&userinfo_endpoint, | ||
ACCESS_TOKEN, | ||
None, | ||
&auth_id_token, | ||
) | ||
.await | ||
.unwrap(); | ||
let claims = fetch_userinfo(&http_client, &userinfo_endpoint, ACCESS_TOKEN, None) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(claims.get("email").unwrap(), "[email protected]"); | ||
} | ||
|
||
#[tokio::test] | ||
async fn fail_wrong_subject_identifier() { | ||
let (http_client, mock_server, issuer) = init_test().await; | ||
let userinfo_endpoint = issuer.join("userinfo").unwrap(); | ||
let (auth_id_token, _) = id_token(issuer.as_str()); | ||
|
||
Mock::given(method("GET")) | ||
.and(path("/userinfo")) | ||
.and(header( | ||
"authorization", | ||
format!("Bearer {ACCESS_TOKEN}").as_str(), | ||
)) | ||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ | ||
"sub": "wrong_subject_identifier", | ||
"email": "[email protected]", | ||
}))) | ||
.mount(&mock_server) | ||
.await; | ||
|
||
let error = fetch_userinfo( | ||
&http_client, | ||
&userinfo_endpoint, | ||
ACCESS_TOKEN, | ||
None, | ||
&auth_id_token, | ||
) | ||
.await | ||
.unwrap_err(); | ||
|
||
assert_matches!( | ||
error, | ||
UserInfoError::IdToken(IdTokenError::WrongSubjectIdentifier) | ||
); | ||
} |