-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmethod.rs
More file actions
76 lines (63 loc) · 1.85 KB
/
Copy pathmethod.rs
File metadata and controls
76 lines (63 loc) · 1.85 KB
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
use async_trait::async_trait;
use shield::{Method, MethodAction, ShieldError, erased_method};
use workos::Client;
use crate::{
actions::{WorkosIndexAction, WorkosSignInAction, WorkosSignUpAction},
options::WorkosOptions,
provider::WorkosProvider,
};
// TODO: Add hook for WorkOS sign out.
pub const WORKOS_METHOD_ID: &str = "workos";
pub struct WorkosMethod {
options: WorkosOptions,
client: Client,
}
impl WorkosMethod {
pub fn new(client: Client, options: WorkosOptions) -> Self {
Self { options, client }
}
pub fn from_api_key(api_key: &str, client_id: &str, options: WorkosOptions) -> Self {
Self::new(
Client::builder()
.api_key(api_key)
.client_id(client_id)
.build(),
options,
)
}
pub fn with_options(mut self, options: WorkosOptions) -> Self {
self.options = options;
self
}
}
#[async_trait]
impl Method for WorkosMethod {
type Provider = WorkosProvider;
type Connection = ();
type Session = ();
fn id(&self) -> String {
WORKOS_METHOD_ID.to_owned()
}
fn actions(&self) -> Vec<Box<dyn MethodAction<Self::Provider, Self::Session>>> {
vec![
Box::new(WorkosIndexAction::new(
self.options.clone(),
self.client.clone(),
)),
Box::new(WorkosSignInAction::new(self.client.clone())),
Box::new(WorkosSignUpAction::new(self.client.clone())),
]
}
async fn providers(&self) -> Result<Vec<Self::Provider>, ShieldError> {
Ok(vec![WorkosProvider])
}
async fn user_connections(
&self,
_user_id: &str,
_provider_id: Option<&str>,
) -> Result<Vec<Self::Connection>, ShieldError> {
// TODO
Ok(vec![])
}
}
erased_method!(WorkosMethod);