ezidam, openid: check scopes, check response types before getting app
This commit is contained in:
parent
396856eee5
commit
8ae0c59a25
7 changed files with 98 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use itertools::Itertools;
|
||||
use openidconnect::Scope;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct SupportedScopes(pub Vec<Scope>);
|
||||
|
||||
|
|
@ -7,6 +8,16 @@ impl SupportedScopes {
|
|||
pub fn url_format() -> String {
|
||||
Self::default().0.iter().map(|s| s.as_str()).join(" ")
|
||||
}
|
||||
pub fn check_supported_scopes(scopes: &str) -> bool {
|
||||
if scopes.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let list = Self::default();
|
||||
let scope_set: &HashSet<_> = &list.0.iter().map(|s| s.as_str()).collect();
|
||||
let requested_scopes: HashSet<_> = scopes.split_whitespace().collect();
|
||||
requested_scopes.is_subset(scope_set)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SupportedScopes {
|
||||
|
|
@ -18,3 +29,25 @@ impl Default for SupportedScopes {
|
|||
])
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::SupportedScopes;
|
||||
|
||||
#[test]
|
||||
fn check_valid() {
|
||||
assert!(SupportedScopes::check_supported_scopes("openid"));
|
||||
assert!(SupportedScopes::check_supported_scopes("profile email"));
|
||||
assert!(SupportedScopes::check_supported_scopes("email openid"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_invalid() {
|
||||
assert!(!SupportedScopes::check_supported_scopes(""));
|
||||
assert!(!SupportedScopes::check_supported_scopes("openid abc"));
|
||||
assert!(!SupportedScopes::check_supported_scopes("test"));
|
||||
assert!(!SupportedScopes::check_supported_scopes(
|
||||
"email testing wrong profile"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue