1use oauth2_client::re_exports::{
2 Deserialize_enum_str, Scope, Serialize_enum_str, Url, UrlParseError,
3};
4
5pub const BASE_URL_GITLAB_COM: &str = "https://gitlab.com/";
6
7pub mod authorization_code_grant;
8
9pub use authorization_code_grant::GitlabProviderForEndUsers;
10
11pub mod extensions;
12pub use extensions::GitlabExtensionsBuilder;
13
14pub fn token_url(base_url: impl AsRef<str>) -> Result<Url, UrlParseError> {
15 Url::parse(base_url.as_ref())?.join("/oauth/token")
16}
17pub fn authorization_url(base_url: impl AsRef<str>) -> Result<Url, UrlParseError> {
18 Url::parse(base_url.as_ref())?.join("/oauth/authorize")
19}
20
21#[derive(Deserialize_enum_str, Serialize_enum_str, Debug, Clone, PartialEq, Eq)]
23pub enum GitlabScope {
24 #[serde(rename = "api")]
25 Api,
26 #[serde(rename = "read_user")]
27 ReadUser,
28 #[serde(rename = "read_api")]
29 ReadApi,
30 #[serde(rename = "read_repository")]
31 ReadRepository,
32 #[serde(rename = "write_repository")]
33 WriteRepository,
34 #[serde(rename = "read_registry")]
35 ReadRegistry,
36 #[serde(rename = "write_registry")]
37 WriteRegistry,
38 #[serde(rename = "sudo")]
39 Sudo,
40 #[serde(rename = "openid")]
41 Openid,
42 #[serde(rename = "profile")]
43 Profile,
44 #[serde(rename = "email")]
45 Email,
46 #[serde(other)]
50 Other(String),
51}
52impl Scope for GitlabScope {}
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_token_url() {
60 assert_eq!(
61 token_url("https://mastodon.social/").unwrap().as_str(),
62 "https://mastodon.social/oauth/token"
63 );
64 assert_eq!(
65 token_url("https://mastodon.social").unwrap().as_str(),
66 "https://mastodon.social/oauth/token"
67 );
68 }
69
70 #[test]
71 fn test_authorization_url() {
72 assert_eq!(
73 authorization_url("https://mastodon.social/")
74 .unwrap()
75 .as_str(),
76 "https://mastodon.social/oauth/authorize"
77 );
78 assert_eq!(
79 authorization_url("https://mastodon.social")
80 .unwrap()
81 .as_str(),
82 "https://mastodon.social/oauth/authorize"
83 );
84 }
85}