ramp_api/
auths.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Auths {
5    pub client: Client,
6}
7
8impl Auths {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Auths { client }
12    }
13
14    /**
15     * Get OAuth2 token.
16     *
17     * This function performs a `POST` to the `/token` endpoint.
18     *
19     * Returns an access token for accessing endpoints. There are three methods to get an access token:
20     * * "authorization\_code": Authorization Code Grant method, used for retrieving an access token for the first time
21     * * "refresh\_token": Refresh Token method, used for retrieving subsequent access tokens using the refresh token provided from authorization code grant
22     * * "client\_credentials": Client Credentials method, allows direct retrieval of access tokens with only client id and secret.
23     *
24     * There are two main flows: Authorization Code Grant + Refresh Token; or Client Credentials.
25     *
26     * For Authorization Code Grant + Refresh Token, the flow would be as follows:
27     * * Follow authorization process to get an authorization code
28     * * Use authorization code to retrieve an access token and refresh token from this endpoint
29     * * Use refresh token to retrieve new access tokens from this endpoint (without having to go through authorization process again)
30     *
31     * For Client Credentials:
32     * * Call token endpoint with client credentials to retrieve access token
33     *
34     * The request body is different for the methods:
35     * * grant\_type = "authorization\_code"
36     *   * code
37     *   * redirect\_uri
38     * * grant\_type = "refresh\_token"
39     *   * refresh\_token
40     * * grant\_type = "client\_credentials"
41     *   * no additional data
42     *
43     * Some important notes:
44     * * Unlike other endpoints, the data format must be "application/x-www-form-urlencoded", according to [RFC specifications](https://datatracker.ietf.org/doc/html/rfc6749#appendix-B)
45     * * To use a particular code grant, it must be included in the "Grant Types" section of the App Settings modal in app.ramp.com
46     * * Only the authorization code grant returns a refresh token
47     *   * Additionally, the "Refresh Token" grant type must be selected in App Settings for the refresh token to be returned
48     * * The token endpoint used to be "/public/v1/customer/token" - this endpoint is now deprecated and should not be used
49     *
50     * **Parameters:**
51     *
52     * * `authorization: &str` -- Basic \<base64-encoded client_id:client_secret\>.
53     */
54    pub async fn post_token(&self) -> ClientResult<crate::Response<crate::types::OAuth2Token>> {
55        let url = self.client.url("/token", None);
56        self.client
57            .post(
58                &url,
59                crate::Message {
60                    body: None,
61                    content_type: Some("application/x-www-form-urlencoded".to_string()),
62                },
63            )
64            .await
65    }
66}