create_rust_app/auth/oidc/
mod.rs1pub mod controller;
2mod model;
3
4mod schema;
5
6#[derive(Clone)]
7pub struct OIDCProvider {
8 pub name: String,
9 pub client_id: String,
10 pub client_secret: String,
11 pub scope: Vec<String>,
12 pub issuer_url: String,
14 pub success_uri: String,
16 pub error_uri: String,
18}
19
20type ClientId = String;
21type ClientSecret = String;
22type SuccessURI = String;
23type ErrorURI = String;
24type ProviderFactory = fn(ClientId, ClientSecret, SuccessURI, ErrorURI) -> OIDCProvider;
25
26impl OIDCProvider {
27 pub const GOOGLE: ProviderFactory =
28 |client_id: ClientId,
29 client_secret: ClientSecret,
30 success_uri: SuccessURI,
31 error_uri: ErrorURI| Self {
32 name: "google".to_string(),
33 scope: vec!["email".to_string()],
34 issuer_url: "https://accounts.google.com".to_string(),
35 client_id,
36 client_secret,
37 success_uri,
38 error_uri,
39 };
40
41 #[must_use]
42 pub fn redirect_uri(&self, api_url: impl AsRef<str>) -> String {
43 format!(
44 "{api_url}/api/auth/oidc/{provider_name}/login",
45 api_url = api_url.as_ref(),
46 provider_name = self.name
47 )
48 }
49}