ngrok/config/
oidc.rs

1use crate::internals::proto::{
2    Oidc,
3    SecretString,
4};
5
6/// Oidc Options configuration
7///
8/// https://ngrok.com/docs/http/openid-connect/
9#[derive(Clone, Default)]
10pub struct OidcOptions {
11    issuer_url: String,
12    client_id: String,
13    client_secret: SecretString,
14    allow_emails: Vec<String>,
15    allow_domains: Vec<String>,
16    scopes: Vec<String>,
17}
18
19impl OidcOptions {
20    /// Create a new [OidcOptions] with the given issuer and client information.
21    pub fn new(
22        issuer_url: impl Into<String>,
23        client_id: impl Into<String>,
24        client_secret: impl Into<String>,
25    ) -> Self {
26        OidcOptions {
27            issuer_url: issuer_url.into(),
28            client_id: client_id.into(),
29            client_secret: client_secret.into().into(),
30            ..Default::default()
31        }
32    }
33
34    /// Allow the oidc user with the given email to access the tunnel.
35    pub fn allow_email(&mut self, email: impl Into<String>) -> &mut Self {
36        self.allow_emails.push(email.into());
37        self
38    }
39    /// Allow the oidc user with the given email domain to access the tunnel.
40    pub fn allow_domain(&mut self, domain: impl Into<String>) -> &mut Self {
41        self.allow_domains.push(domain.into());
42        self
43    }
44    /// Request the given scope from the oidc provider.
45    pub fn scope(&mut self, scope: impl Into<String>) -> &mut Self {
46        self.scopes.push(scope.into());
47        self
48    }
49}
50
51// transform into the wire protocol format
52impl From<OidcOptions> for Oidc {
53    fn from(o: OidcOptions) -> Self {
54        Oidc {
55            issuer_url: o.issuer_url,
56            client_id: o.client_id,
57            client_secret: o.client_secret,
58            sealed_client_secret: Default::default(), // unused in this context
59            allow_emails: o.allow_emails,
60            allow_domains: o.allow_domains,
61            scopes: o.scopes,
62        }
63    }
64}