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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#[cfg(any(feature = "microsoft", doc))]
pub mod microsoft;
use url::Url;
pub trait Provider {
fn auth_uri(&self) -> &Url;
fn token_uri(&self) -> &Url;
fn credentials_in_body(&self) -> bool {
false
}
}
pub mod google {
use super::Provider;
use url::Url;
pub const REDIRECT_URI_OOB: &str = "urn:ietf:wg:oauth:2.0:oob";
pub const REDIRECT_URI_OOB_AUTO: &str = "urn:ietf:wg:oauth:2.0:oob:auto";
lazy_static! {
static ref AUTH_URI: Url =
Url::parse("https://accounts.google.com/o/oauth2/v2/auth").unwrap();
static ref TOKEN_URI: Url =
Url::parse("https://www.googleapis.com/oauth2/v4/token").unwrap();
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Web;
impl Provider for Web {
fn auth_uri(&self) -> &Url {
&AUTH_URI
}
fn token_uri(&self) -> &Url {
&TOKEN_URI
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Installed;
impl Provider for Installed {
fn auth_uri(&self) -> &Url {
&AUTH_URI
}
fn token_uri(&self) -> &Url {
&TOKEN_URI
}
}
}
lazy_static! {
static ref GITHUB_AUTH_URI: Url =
Url::parse("https://github.com/login/oauth/authorize").unwrap();
static ref GITHUB_TOKEN_URI: Url =
Url::parse("https://github.com/login/oauth/access_token").unwrap();
static ref IMGUR_AUTH_URI: Url = Url::parse("https://api.imgur.com/oauth2/authorize").unwrap();
static ref IMGUR_TOKEN_URI: Url = Url::parse("https://api.imgur.com/oauth2/token").unwrap();
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct GitHub;
impl Provider for GitHub {
fn auth_uri(&self) -> &Url {
&GITHUB_AUTH_URI
}
fn token_uri(&self) -> &Url {
&GITHUB_TOKEN_URI
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Imgur;
impl Provider for Imgur {
fn auth_uri(&self) -> &Url {
&IMGUR_AUTH_URI
}
fn token_uri(&self) -> &Url {
&IMGUR_TOKEN_URI
}
}
#[test]
fn google_urls() {
let prov = google::Web;
prov.auth_uri();
prov.token_uri();
let prov = google::Installed;
prov.auth_uri();
prov.token_uri();
}
#[test]
fn github_urls() {
let prov = GitHub;
prov.auth_uri();
prov.token_uri();
}
#[test]
fn imgur_urls() {
let prov = Imgur;
prov.auth_uri();
prov.token_uri();
}