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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Code generated by sdkgen. DO NOT EDIT.
//! Generated native types and clients for authentication.proto.
use crate::codec::authentication::{
from_wire_auth_session_settings, from_wire_authenticated_user, from_wire_begin_login_response,
to_wire_begin_login_request, to_wire_complete_login_request,
to_wire_validate_external_token_request,
};
use crate::generated::v1;
use crate::rpc_support::GestaltError;
/// AuthSessionSettings configures how the host persists authenticated sessions.
///
/// Native message type for `gestalt.provider.v1.AuthSessionSettings`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct AuthSessionSettings {
/// The `session_ttl_seconds` field.
pub session_ttl_seconds: i64,
}
/// AuthenticatedUser is the normalized user identity returned by an authentication
/// provider after a login or token-validation flow.
///
/// Native message type for `gestalt.provider.v1.AuthenticatedUser`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct AuthenticatedUser {
/// The `subject` field.
pub subject: String,
/// The `email` field.
pub email: String,
/// The `email_verified` field.
pub email_verified: bool,
/// The `display_name` field.
pub display_name: String,
/// The `avatar_url` field.
pub avatar_url: String,
/// The `claims` field.
pub claims: std::collections::BTreeMap<String, String>,
}
/// BeginLoginRequest starts an interactive login flow.
///
/// Native message type for `gestalt.provider.v1.BeginLoginRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct BeginLoginRequest {
/// callback_url is the host-managed URL the provider should redirect back to.
///
/// The `callback_url` field.
pub callback_url: String,
/// host_state is opaque state generated by the host and echoed back on
/// completion.
///
/// The `host_state` field.
pub host_state: String,
/// scopes are the provider-specific scopes the host is requesting.
///
/// The `scopes` field.
pub scopes: Vec<String>,
/// options carries provider-specific login parameters.
///
/// The `options` field.
pub options: std::collections::BTreeMap<String, String>,
}
/// BeginLoginResponse returns the provider-managed authorization URL and opaque
/// provider state that must be preserved until completion.
///
/// Native message type for `gestalt.provider.v1.BeginLoginResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct BeginLoginResponse {
/// The `authorization_url` field.
pub authorization_url: String,
/// The `provider_state` field.
pub provider_state: Vec<u8>,
}
/// CompleteLoginRequest finishes an interactive login flow.
///
/// Native message type for `gestalt.provider.v1.CompleteLoginRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct CompleteLoginRequest {
/// query contains the callback URL query parameters returned by the identity
/// provider.
///
/// The `query` field.
pub query: std::collections::BTreeMap<String, String>,
/// provider_state is the opaque state returned from BeginLoginResponse.
///
/// The `provider_state` field.
pub provider_state: Vec<u8>,
/// callback_url is the fully qualified callback URL used by the host.
///
/// The `callback_url` field.
pub callback_url: String,
}
/// ValidateExternalTokenRequest asks the provider to validate a token minted
/// outside the interactive login flow.
///
/// Native message type for `gestalt.provider.v1.ValidateExternalTokenRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ValidateExternalTokenRequest {
/// The `token` field.
pub token: String,
}
/// Authentication models the shared Gestalt authentication protocol.
///
/// Client for the `gestalt.provider.v1.Authentication` service.
pub struct Authentication {
inner: v1::authentication_client::AuthenticationClient<tonic::transport::Channel>,
timeout: Option<std::time::Duration>,
}
impl Authentication {
/// Creates a client over an established channel.
pub fn new(channel: tonic::transport::Channel) -> Self {
Self {
inner: v1::authentication_client::AuthenticationClient::new(channel),
timeout: None,
}
}
/// Sets a deadline applied to every unary call; calls that run past it
/// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
self.timeout = Some(timeout);
self
}
/// Calls `gestalt.provider.v1.Authentication.BeginLogin`.
pub async fn begin_login(
&mut self,
callback_url: String,
host_state: String,
scopes: Vec<String>,
) -> Result<BeginLoginResponse, GestaltError> {
let request = BeginLoginRequest {
callback_url,
host_state,
scopes,
..Default::default()
};
let mut tonic_request = tonic::Request::new(to_wire_begin_login_request(request));
if let Some(timeout) = self.timeout {
tonic_request.set_timeout(timeout);
}
let response = self.inner.begin_login(tonic_request).await?;
Ok(from_wire_begin_login_response(response.into_inner()))
}
/// Calls `gestalt.provider.v1.Authentication.BeginLogin` with the full request and response messages.
pub async fn begin_login_raw(
&mut self,
request: BeginLoginRequest,
) -> Result<BeginLoginResponse, GestaltError> {
let mut tonic_request = tonic::Request::new(to_wire_begin_login_request(request));
if let Some(timeout) = self.timeout {
tonic_request.set_timeout(timeout);
}
let response = self.inner.begin_login(tonic_request).await?;
Ok(from_wire_begin_login_response(response.into_inner()))
}
/// Calls `gestalt.provider.v1.Authentication.CompleteLogin`.
pub async fn complete_login(
&mut self,
provider_state: Vec<u8>,
callback_url: String,
query: std::collections::BTreeMap<String, String>,
) -> Result<AuthenticatedUser, GestaltError> {
let request = CompleteLoginRequest {
provider_state,
callback_url,
query,
};
let mut tonic_request = tonic::Request::new(to_wire_complete_login_request(request));
if let Some(timeout) = self.timeout {
tonic_request.set_timeout(timeout);
}
let response = self.inner.complete_login(tonic_request).await?;
Ok(from_wire_authenticated_user(response.into_inner()))
}
/// Calls `gestalt.provider.v1.Authentication.CompleteLogin` with the full request and response messages.
pub async fn complete_login_raw(
&mut self,
request: CompleteLoginRequest,
) -> Result<AuthenticatedUser, GestaltError> {
let mut tonic_request = tonic::Request::new(to_wire_complete_login_request(request));
if let Some(timeout) = self.timeout {
tonic_request.set_timeout(timeout);
}
let response = self.inner.complete_login(tonic_request).await?;
Ok(from_wire_authenticated_user(response.into_inner()))
}
/// Calls `gestalt.provider.v1.Authentication.ValidateExternalToken`.
pub async fn validate_external_token(
&mut self,
token: String,
) -> Result<AuthenticatedUser, GestaltError> {
let request = ValidateExternalTokenRequest { token };
let mut tonic_request =
tonic::Request::new(to_wire_validate_external_token_request(request));
if let Some(timeout) = self.timeout {
tonic_request.set_timeout(timeout);
}
let response = self.inner.validate_external_token(tonic_request).await?;
Ok(from_wire_authenticated_user(response.into_inner()))
}
/// Calls `gestalt.provider.v1.Authentication.ValidateExternalToken` with the full request and response messages.
pub async fn validate_external_token_raw(
&mut self,
request: ValidateExternalTokenRequest,
) -> Result<AuthenticatedUser, GestaltError> {
let mut tonic_request =
tonic::Request::new(to_wire_validate_external_token_request(request));
if let Some(timeout) = self.timeout {
tonic_request.set_timeout(timeout);
}
let response = self.inner.validate_external_token(tonic_request).await?;
Ok(from_wire_authenticated_user(response.into_inner()))
}
/// Calls `gestalt.provider.v1.Authentication.GetSessionSettings`.
pub async fn get_session_settings(&mut self) -> Result<AuthSessionSettings, GestaltError> {
let mut tonic_request = tonic::Request::new(());
if let Some(timeout) = self.timeout {
tonic_request.set_timeout(timeout);
}
let response = self.inner.get_session_settings(tonic_request).await?;
Ok(from_wire_auth_session_settings(response.into_inner()))
}
}