graph_oauth/identity/credentials/
prompt.rs

1use std::collections::BTreeSet;
2
3use crate::identity::credentials::as_query::AsQuery;
4
5/// Indicates the type of user interaction that is required. Valid values are login, none,
6/// consent, and select_account.
7///
8/// - **prompt=login** forces the user to enter their credentials on that request, negating single-sign on.
9/// - **prompt=none** is the opposite. It ensures that the user isn't presented with any interactive prompt.
10///     If the request can't be completed silently by using single-sign on, the Microsoft identity platform returns an interaction_required error.
11/// - **prompt=consent** triggers the OAuth consent dialog after the user signs in, asking the user to
12///     grant permissions to the app.
13/// - **prompt=select_account** interrupts single sign-on providing account selection experience
14///     listing all the accounts either in session or any remembered account or an option to choose to use a different account altogether.
15#[derive(Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum Prompt {
17    #[default]
18    None,
19    /// The user will be prompted for credentials by the service.
20    Login,
21    /// The user will be prompted to consent even if consent was granted before.
22    Consent,
23    /// The user will be prompted with a list of accounts from which one can be selected
24    /// for authentication.
25    SelectAccount,
26    /// Use only for federated users. Provides same functionality as prompt=none
27    /// for managed users.
28    AttemptNone,
29}
30
31impl AsRef<str> for Prompt {
32    fn as_ref(&self) -> &'static str {
33        match self {
34            Prompt::None => "none",
35            Prompt::Login => "login",
36            Prompt::Consent => "consent",
37            Prompt::SelectAccount => "select_account",
38            Prompt::AttemptNone => "attempt_none",
39        }
40    }
41}
42
43impl IntoIterator for Prompt {
44    type Item = Prompt;
45    type IntoIter = std::vec::IntoIter<Self::Item>;
46
47    fn into_iter(self) -> Self::IntoIter {
48        vec![self].into_iter()
49    }
50}
51
52impl AsQuery for Vec<Prompt> {
53    fn as_query(&self) -> String {
54        self.iter()
55            .map(|s| s.as_ref())
56            .collect::<Vec<&str>>()
57            .join(" ")
58    }
59}
60
61impl AsQuery for BTreeSet<Prompt> {
62    fn as_query(&self) -> String {
63        self.iter()
64            .map(|s| s.as_ref())
65            .collect::<Vec<&str>>()
66            .join(" ")
67    }
68}