Skip to content

Commit

Permalink
Add AuthorizationRequest::add_scopes (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmari-h authored Mar 22, 2023
1 parent 8e550ab commit d177811
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,17 @@ where
self
}

///
/// Appends a collection of scopes to the authorization URL.
///
pub fn add_scopes<I>(mut self, scopes: I) -> Self
where
I: IntoIterator<Item = Scope>,
{
self.inner = self.inner.add_scopes(scopes);
self
}

///
/// Appends an extra param to the authorization URL.
///
Expand Down Expand Up @@ -1602,7 +1613,7 @@ mod tests {
.unwrap();

let (authorize_url, _, _) = client
.authorize_url(flow, new_csrf, new_nonce)
.authorize_url(flow.clone(), new_csrf, new_nonce)
.add_scope(Scope::new("email".to_string()))
.set_display(CoreAuthDisplay::Touch)
.set_id_token_hint(&id_token)
Expand All @@ -1629,6 +1640,38 @@ mod tests {
),
authorize_url.to_string()
);

let (authorize_url, _, _) = client
.authorize_url(flow.clone(), new_csrf, new_nonce)
.add_scopes(vec![
Scope::new("email".to_string()),
Scope::new("profile".to_string()),
])
.set_display(CoreAuthDisplay::Touch)
.set_id_token_hint(&id_token)
.set_login_hint(LoginHint::new("foo@bar.com".to_string()))
.add_prompt(CoreAuthPrompt::Login)
.add_prompt(CoreAuthPrompt::Consent)
.set_max_age(Duration::from_secs(1800))
.add_ui_locale(LanguageTag::new("fr-CA".to_string()))
.add_ui_locale(LanguageTag::new("fr".to_string()))
.add_ui_locale(LanguageTag::new("en".to_string()))
.add_auth_context_value(AuthenticationContextClass::new(
"urn:mace:incommon:iap:silver".to_string(),
))
.add_extra_param("foo", "bar")
.url();
assert_eq!(
format!(
"https://example/authorize?response_type=code&client_id=aaa&state=CSRF123&\
redirect_uri=http%3A%2F%2Flocalhost%3A8888%2F&scope=openid+email+profile&foo=bar&\
nonce=NONCE456&acr_values=urn%3Amace%3Aincommon%3Aiap%3Asilver&display=touch&\
id_token_hint={}&login_hint=foo%40bar.com&\
max_age=1800&prompt=login+consent&ui_locales=fr-CA+fr+en",
serialized_jwt
),
authorize_url.to_string()
);
}

#[test]
Expand Down

0 comments on commit d177811

Please sign in to comment.