1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use anyhow::Result;

use crate::Client;

pub struct Login {
    pub client: Client,
}

impl Login {
    #[doc(hidden)]
    pub fn new(client: Client) -> Self {
        Login { client }
    }

    /**
     * Prompt user login.
     *
     * This function performs a `GET` to the `/login/{silo_name}/{provider_name}` endpoint.
     *
     * Either display a page asking a user for their credentials, or redirect them to their identity provider.
     *
     * **Parameters:**
     *
     * * `provider_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
     * * `silo_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
     */
    pub async fn get(&self, provider_name: &str, silo_name: &str) -> Result<()> {
        let url = format!(
            "/login/{}/{}",
            crate::progenitor_support::encode_path(silo_name),
            crate::progenitor_support::encode_path(provider_name),
        );

        self.client.get(&url, None).await
    }

    /**
     * Authenticate a user.
     *
     * This function performs a `POST` to the `/login/{silo_name}/{provider_name}` endpoint.
     *
     * Either receive a username and password, or some sort of identity provider data (like a SAMLResponse). Use these to set the user's session cookie.
     *
     * **Parameters:**
     *
     * * `provider_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
     * * `silo_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
     */
    pub async fn consume_credentials<B: Into<reqwest::Body>>(
        &self,
        provider_name: &str,
        silo_name: &str,
        body: B,
    ) -> Result<()> {
        let url = format!(
            "/login/{}/{}",
            crate::progenitor_support::encode_path(silo_name),
            crate::progenitor_support::encode_path(provider_name),
        );

        self.client.post(&url, Some(body.into())).await
    }
}