oxide_api/
login.rs

1use anyhow::Result;
2
3use crate::Client;
4
5pub struct Login {
6    pub client: Client,
7}
8
9impl Login {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Login { client }
13    }
14
15    /**
16     * Prompt user login.
17     *
18     * This function performs a `GET` to the `/login/{silo_name}/{provider_name}` endpoint.
19     *
20     * Either display a page asking a user for their credentials, or redirect them to their identity provider.
21     *
22     * **Parameters:**
23     *
24     * * `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.
25     * * `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.
26     */
27    pub async fn get(&self, provider_name: &str, silo_name: &str) -> Result<()> {
28        let url = format!(
29            "/login/{}/{}",
30            crate::progenitor_support::encode_path(silo_name),
31            crate::progenitor_support::encode_path(provider_name),
32        );
33
34        self.client.get(&url, None).await
35    }
36
37    /**
38     * Authenticate a user.
39     *
40     * This function performs a `POST` to the `/login/{silo_name}/{provider_name}` endpoint.
41     *
42     * 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.
43     *
44     * **Parameters:**
45     *
46     * * `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.
47     * * `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.
48     */
49    pub async fn consume_credentials<B: Into<reqwest::Body>>(
50        &self,
51        provider_name: &str,
52        silo_name: &str,
53        body: B,
54    ) -> Result<()> {
55        let url = format!(
56            "/login/{}/{}",
57            crate::progenitor_support::encode_path(silo_name),
58            crate::progenitor_support::encode_path(provider_name),
59        );
60
61        self.client.post(&url, Some(body.into())).await
62    }
63}