okta/sessions.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Sessions {
5 pub client: Client,
6}
7
8impl Sessions {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Sessions { client }
12 }
13
14 /**
15 * Create Session with Session Token.
16 *
17 * This function performs a `POST` to the `/api/v1/sessions` endpoint.
18 *
19 * Creates a new session for a user with a valid session token. Use this API if, for example, you want to set the session cookie yourself instead of allowing Okta to set it, or want to hold the session ID in order to delete a session via the API instead of visiting the logout URL.
20 */
21 pub async fn create(
22 &self,
23 body: &crate::types::CreateSessionRequest,
24 ) -> ClientResult<crate::Response<crate::types::Session>> {
25 let url = self.client.url("/api/v1/sessions", None);
26 self.client
27 .post(
28 &url,
29 crate::Message {
30 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
31 content_type: Some("application/json".to_string()),
32 },
33 )
34 .await
35 }
36 /**
37 * This function performs a `GET` to the `/api/v1/sessions/{sessionId}` endpoint.
38 *
39 * Get details about a session.
40 *
41 * **Parameters:**
42 *
43 * * `session_id: &str`
44 */
45 pub async fn get(
46 &self,
47 session_id: &str,
48 ) -> ClientResult<crate::Response<crate::types::Session>> {
49 let url = self.client.url(
50 &format!(
51 "/api/v1/sessions/{}",
52 crate::progenitor_support::encode_path(session_id),
53 ),
54 None,
55 );
56 self.client
57 .get(
58 &url,
59 crate::Message {
60 body: None,
61 content_type: None,
62 },
63 )
64 .await
65 }
66 /**
67 * Close Session.
68 *
69 * This function performs a `DELETE` to the `/api/v1/sessions/{sessionId}` endpoint.
70 *
71 *
72 *
73 * **Parameters:**
74 *
75 * * `session_id: &str`
76 */
77 pub async fn end(&self, session_id: &str) -> ClientResult<crate::Response<()>> {
78 let url = self.client.url(
79 &format!(
80 "/api/v1/sessions/{}",
81 crate::progenitor_support::encode_path(session_id),
82 ),
83 None,
84 );
85 self.client
86 .delete(
87 &url,
88 crate::Message {
89 body: None,
90 content_type: None,
91 },
92 )
93 .await
94 }
95 /**
96 * Refresh Session.
97 *
98 * This function performs a `POST` to the `/api/v1/sessions/{sessionId}/lifecycle/refresh` endpoint.
99 *
100 *
101 *
102 * **Parameters:**
103 *
104 * * `session_id: &str`
105 */
106 pub async fn refresh(
107 &self,
108 session_id: &str,
109 ) -> ClientResult<crate::Response<crate::types::Session>> {
110 let url = self.client.url(
111 &format!(
112 "/api/v1/sessions/{}/lifecycle/refresh",
113 crate::progenitor_support::encode_path(session_id),
114 ),
115 None,
116 );
117 self.client
118 .post(
119 &url,
120 crate::Message {
121 body: None,
122 content_type: None,
123 },
124 )
125 .await
126 }
127}