firebase_rs_sdk/auth/oauth/
mod.rs1pub mod credential;
2pub mod pkce;
3pub mod provider;
4pub mod providers;
5pub mod redirect;
6
7use pkce::PkcePair;
8
9use std::collections::HashMap;
10
11use crate::auth::error::AuthResult;
12use crate::auth::model::AuthCredential;
13
14#[derive(Debug, Clone)]
20pub struct OAuthRequest {
21 pub provider_id: String,
23 pub auth_url: String,
25 pub display_name: Option<String>,
27 pub language_code: Option<String>,
29 pub custom_parameters: HashMap<String, String>,
31 pub pkce: Option<PkcePair>,
33}
34
35impl OAuthRequest {
36 pub fn new(provider_id: impl Into<String>, auth_url: impl Into<String>) -> Self {
37 Self {
38 provider_id: provider_id.into(),
39 auth_url: auth_url.into(),
40 display_name: None,
41 language_code: None,
42 custom_parameters: HashMap::new(),
43 pkce: None,
44 }
45 }
46
47 pub fn with_display_name(mut self, value: impl Into<String>) -> Self {
48 self.display_name = Some(value.into());
49 self
50 }
51
52 pub fn with_language_code(mut self, value: impl Into<String>) -> Self {
53 self.language_code = Some(value.into());
54 self
55 }
56
57 pub fn with_custom_parameters(mut self, parameters: HashMap<String, String>) -> Self {
58 self.custom_parameters = parameters;
59 self
60 }
61
62 pub fn with_pkce(mut self, pkce: Option<PkcePair>) -> Self {
63 self.pkce = pkce;
64 self
65 }
66
67 pub fn pkce(&self) -> Option<&PkcePair> {
68 self.pkce.as_ref()
69 }
70}
71
72pub trait OAuthPopupHandler: Send + Sync {
79 fn open_popup(&self, request: OAuthRequest) -> AuthResult<AuthCredential>;
80}
81
82pub trait OAuthRedirectHandler: Send + Sync {
89 fn initiate_redirect(&self, request: OAuthRequest) -> AuthResult<()>;
90 fn complete_redirect(&self) -> AuthResult<Option<AuthCredential>>;
91}