Skip to main content

max / goingson

2.1 KB · 69 lines History Blame Raw
1 //! Fastmail OAuth2 provider.
2 //!
3 //! Implements OAuth2 with PKCE for Fastmail's JMAP API access.
4 //! Uses ClientIdOnly (no client secret required with PKCE).
5 //!
6 //! See: https://www.fastmail.com/developer/integrating-with-fastmail/
7
8 use crate::oauth::provider::{ClientAuthMethod, OAuthProvider, OAuthProviderConfig};
9
10 /// Fastmail OAuth2 provider.
11 ///
12 /// Uses PKCE with client_id only (no secret required).
13 /// Uses JMAP instead of IMAP.
14 pub struct FastmailProvider {
15 client_id: String,
16 config: OAuthProviderConfig,
17 }
18
19 impl FastmailProvider {
20 /// Creates a new Fastmail OAuth provider.
21 pub fn new(client_id: impl Into<String>) -> Self {
22 Self {
23 client_id: client_id.into(),
24 config: OAuthProviderConfig {
25 auth_url: "https://api.fastmail.com/oauth/authorize".to_string(),
26 token_url: "https://api.fastmail.com/oauth/refresh".to_string(),
27 scopes: vec![
28 "urn:ietf:params:jmap:core".to_string(),
29 "urn:ietf:params:jmap:mail".to_string(),
30 "urn:ietf:params:jmap:submission".to_string(),
31 ],
32 uses_jmap: true,
33 jmap_session_url: Some("https://api.fastmail.com/jmap/session".to_string()),
34 imap_server: None,
35 imap_port: None,
36 smtp_server: None,
37 smtp_port: None,
38 userinfo_url: Some("https://api.fastmail.com/jmap/session".to_string()),
39 email_json_path: vec!["username"], // Fastmail uses "username" for email
40 },
41 }
42 }
43 }
44
45 impl OAuthProvider for FastmailProvider {
46 fn id(&self) -> &'static str {
47 "fastmail"
48 }
49
50 fn display_name(&self) -> &'static str {
51 "Fastmail"
52 }
53
54 fn config(&self) -> &OAuthProviderConfig {
55 &self.config
56 }
57
58 fn client_id(&self) -> &str {
59 &self.client_id
60 }
61
62 fn client_auth_method(&self) -> ClientAuthMethod {
63 // Fastmail uses PKCE, no client secret needed
64 ClientAuthMethod::ClientIdOnly
65 }
66
67 // Uses default exchange_code, refresh_token, get_user_email implementations
68 }
69