Repository navigation
Expand file tree
/
Copy pathidentity_server.rs
More file actions
106 lines (99 loc) · 3.8 KB
/
Copy pathidentity_server.rs
File metadata and controls
106 lines (99 loc) · 3.8 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
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
// Copyright (c) 2025, The Ruskit Authors
// MIT License
// All rights reserved.
//! Defines configuration structures for identity server integration.
//!
//! This module provides configuration options for connecting to and
//! authenticating with identity servers like Auth0, Keycloak, etc.
/// # IdentityServerConfigs
///
/// Configuration structure for identity server integration.
///
/// This structure defines the parameters needed to connect to and authenticate
/// with an identity provider like Auth0, Keycloak, or other OAuth/OpenID Connect
/// compatible identity servers.
///
/// ## Examples
///
/// ```
/// use configs::IdentityServerConfigs;
///
/// let identity_config = IdentityServerConfigs::default();
/// // Configure with actual values before use
/// ```
#[derive(Debug, Clone)]
pub struct IdentityServerConfigs {
/// ENV KEY: "IDENTITY_SERVER_URL"
///
/// Identity Server URL (Default: "")
pub url: String,
/// ENV KEY: "IDENTITY_SERVER_REALM"
///
/// Identity Application Realm (Default: "")
///
/// In Auth0, Realm is the same as Domain
pub realm: String,
/// ENV KEY: "IDENTITY_SERVER_AUDIENCE"
///
/// OAuth audience value (Default: "")
pub audience: String,
/// ENV KEY: "IDENTITY_SERVER_ISSUER"
///
/// OAuth token issuer (Default: "")
pub issuer: String,
/// ENV KEY: "IDENTITY_SERVER_CLIENT_ID"
///
/// OAuth client ID (Default: "")
pub client_id: String,
/// ENV KEY: "IDENTITY_SERVER_CLIENT_SECRET"
///
/// OAuth client secret (Default: "")
pub client_secret: String,
/// ENV KEY: "IDENTITY_SERVER_GRANT_TYPE"
///
/// OAuth grant type (Default: "client_credentials")
pub grant_type: String,
}
pub const IDENTITY_SERVER_URL_ENV_KEY: &str = "IDENTITY_SERVER_URL";
pub const IDENTITY_SERVER_REALM_ENV_KEY: &str = "IDENTITY_SERVER_REALM";
pub const IDENTITY_SERVER_AUDIENCE_ENV_KEY: &str = "IDENTITY_SERVER_AUDIENCE";
pub const IDENTITY_SERVER_ISSUER_ENV_KEY: &str = "IDENTITY_SERVER_ISSUER";
pub const IDENTITY_SERVER_GRANT_TYPE_ENV_KEY: &str = "IDENTITY_SERVER_GRANT_TYPE";
pub const IDENTITY_SERVER_CLIENT_ID_ENV_KEY: &str = "IDENTITY_SERVER_CLIENT_ID";
pub const IDENTITY_SERVER_CLIENT_SECRET_ENV_KEY: &str = "IDENTITY_SERVER_CLIENT_SECRET";
impl IdentityServerConfigs {
/// Creates a new `IdentityServerConfigs` instance from environment variables.
///
/// This method initializes the identity server configuration from environment variables
/// for URL, realm, audience, issuer, client ID, client secret, and grant type.
///
/// ## Returns
///
/// A new `IdentityServerConfigs` from environment variables.
pub fn new() -> Self {
let mut cfgs = Self::default();
cfgs.url = std::env::var(IDENTITY_SERVER_URL_ENV_KEY).unwrap_or(cfgs.url);
cfgs.realm = std::env::var(IDENTITY_SERVER_REALM_ENV_KEY).unwrap_or(cfgs.realm);
cfgs.audience = std::env::var(IDENTITY_SERVER_AUDIENCE_ENV_KEY).unwrap_or(cfgs.audience);
cfgs.issuer = std::env::var(IDENTITY_SERVER_ISSUER_ENV_KEY).unwrap_or(cfgs.issuer);
cfgs.client_id = std::env::var(IDENTITY_SERVER_CLIENT_ID_ENV_KEY).unwrap_or(cfgs.client_id);
cfgs.client_secret =
std::env::var(IDENTITY_SERVER_CLIENT_SECRET_ENV_KEY).unwrap_or(cfgs.client_secret);
cfgs.grant_type =
std::env::var(IDENTITY_SERVER_GRANT_TYPE_ENV_KEY).unwrap_or(cfgs.grant_type);
cfgs
}
}
impl Default for IdentityServerConfigs {
fn default() -> Self {
Self {
url: Default::default(),
realm: Default::default(),
audience: Default::default(),
issuer: Default::default(),
client_id: Default::default(),
client_secret: Default::default(),
grant_type: "client_credentials".to_owned(),
}
}
}