clerk_rs/apis/
configuration.rs1use crate::clerk::USER_AGENT;
2use reqwest::header::{HeaderMap, AUTHORIZATION, USER_AGENT as REQWEST_USER_AGENT};
3
4#[derive(Debug, Clone)]
11pub struct ClerkConfiguration {
12 pub base_path: String,
13 pub user_agent: Option<String>,
14 pub client: reqwest::Client,
15 pub basic_auth: Option<BasicAuth>,
16 pub oauth_access_token: Option<String>,
17 pub bearer_access_token: Option<String>,
18 pub api_key: Option<ApiKey>,
19 }
21
22pub type BasicAuth = (String, Option<String>);
24
25#[derive(Debug, Clone)]
26pub struct ApiKey {
27 pub prefix: Option<String>,
28 pub key: String,
29}
30
31impl ClerkConfiguration {
32 pub fn new(
34 basic_auth: Option<BasicAuth>,
35 oauth_access_token: Option<String>,
36 bearer_access_token: Option<String>,
37 api_key: Option<ApiKey>,
38 ) -> Self {
39 let construct_bearer_token = format!("Bearer {}", bearer_access_token.as_ref().unwrap_or(&String::from("")));
41 let mut headers = HeaderMap::new();
43 headers.insert(REQWEST_USER_AGENT, USER_AGENT.parse().unwrap());
44 headers.insert(
45 AUTHORIZATION,
46 construct_bearer_token
47 .parse()
48 .expect("Error: could not parse Bearer auth token into a valid request header."),
49 );
50
51 let client = reqwest::Client::builder()
53 .default_headers(headers)
54 .build()
55 .expect("Error: could not initialize Clerk SDK client. Please try again!");
56
57 Self {
58 base_path: "https://api.clerk.dev/v1".to_owned(),
59 user_agent: Some(USER_AGENT.to_owned()),
60 client,
61 basic_auth,
62 oauth_access_token,
63 bearer_access_token,
64 api_key,
65 }
66 }
67}
68
69impl Default for ClerkConfiguration {
70 fn default() -> Self {
71 let mut headers = HeaderMap::new();
73 headers.insert(REQWEST_USER_AGENT, USER_AGENT.parse().unwrap());
74 let client = reqwest::Client::builder()
75 .default_headers(headers)
76 .build()
77 .expect("Error: could not initialize Clerk SDK client. Please try again!");
78
79 Self {
80 base_path: "https://api.clerk.dev/v1".to_owned(),
81 user_agent: Some(USER_AGENT.to_owned()),
82 client,
83 basic_auth: None,
84 oauth_access_token: None,
85 bearer_access_token: None,
86 api_key: None,
87 }
88 }
89}