1use std::{fmt::Debug, sync::Arc};
2
3use crate::types::{OAuthCredentials, TokenAuthMethod, UserInfo};
4
5pub trait SimpleOAuthProvider: Debug + Send + Sync {
7 fn authorize_url(&self) -> &str;
9 fn token_url(&self) -> &str;
11 fn default_scopes(&self) -> &'static [&'static str] {
13 &[]
14 }
15 fn token_auth_method(&self) -> TokenAuthMethod {
17 TokenAuthMethod::BasicAuth
18 }
19}
20
21pub trait UserInfoProvider: SimpleOAuthProvider {
23 fn user_info_url(&self) -> &str;
25 fn extract_user_info(&self, val: serde_json::Value) -> Result<UserInfo, serde_json::Error>;
27 fn user_info_headers(&self, _credentials: &OAuthCredentials) -> Vec<(String, String)> {
29 vec![]
30 }
31}
32
33impl<T> SimpleOAuthProvider for Box<T>
34where
35 T: SimpleOAuthProvider + ?Sized,
36{
37 fn authorize_url(&self) -> &str {
38 (**self).authorize_url()
39 }
40 fn token_url(&self) -> &str {
41 (**self).token_url()
42 }
43 fn default_scopes(&self) -> &'static [&'static str] {
44 (**self).default_scopes()
45 }
46 fn token_auth_method(&self) -> TokenAuthMethod {
47 (**self).token_auth_method()
48 }
49}
50
51impl<T> UserInfoProvider for Box<T>
52where
53 T: UserInfoProvider + ?Sized,
54{
55 fn user_info_url(&self) -> &str {
56 (**self).user_info_url()
57 }
58 fn extract_user_info(&self, val: serde_json::Value) -> Result<UserInfo, serde_json::Error> {
59 (**self).extract_user_info(val)
60 }
61 fn user_info_headers(&self, credentials: &OAuthCredentials) -> Vec<(String, String)> {
62 (**self).user_info_headers(credentials)
63 }
64}
65
66impl<T> SimpleOAuthProvider for Arc<T>
67where
68 T: SimpleOAuthProvider + ?Sized,
69{
70 fn authorize_url(&self) -> &str {
71 (**self).authorize_url()
72 }
73 fn token_url(&self) -> &str {
74 (**self).token_url()
75 }
76 fn default_scopes(&self) -> &'static [&'static str] {
77 (**self).default_scopes()
78 }
79 fn token_auth_method(&self) -> TokenAuthMethod {
80 (**self).token_auth_method()
81 }
82}
83
84impl<T> UserInfoProvider for Arc<T>
85where
86 T: UserInfoProvider + ?Sized,
87{
88 fn user_info_url(&self) -> &str {
89 (**self).user_info_url()
90 }
91 fn extract_user_info(&self, val: serde_json::Value) -> Result<UserInfo, serde_json::Error> {
92 (**self).extract_user_info(val)
93 }
94 fn user_info_headers(&self, credentials: &OAuthCredentials) -> Vec<(String, String)> {
95 (**self).user_info_headers(credentials)
96 }
97}