oauth2_dropbox/
authorization_code_grant.rs1use oauth2_client::{
2 authorization_code_grant::provider_ext::ProviderExtAuthorizationCodeGrantPkceSupportType,
3 re_exports::{ClientId, ClientSecret, RedirectUri, Url, UrlParseError},
4 Provider, ProviderExtAuthorizationCodeGrant,
5};
6
7use crate::{DropboxScope, AUTHORIZATION_URL, TOKEN_URL};
8
9#[derive(Debug, Clone)]
10pub struct DropboxProviderWithWebApplication {
11 client_id: ClientId,
12 client_secret: ClientSecret,
13 redirect_uri: RedirectUri,
14 token_endpoint_url: Url,
16 authorization_endpoint_url: Url,
17}
18impl DropboxProviderWithWebApplication {
19 pub fn new(
20 client_id: ClientId,
21 client_secret: ClientSecret,
22 redirect_uri: RedirectUri,
23 ) -> Result<Self, UrlParseError> {
24 Ok(Self {
25 client_id,
26 client_secret,
27 redirect_uri,
28 token_endpoint_url: TOKEN_URL.parse()?,
29 authorization_endpoint_url: AUTHORIZATION_URL.parse()?,
30 })
31 }
32}
33impl Provider for DropboxProviderWithWebApplication {
34 type Scope = DropboxScope;
35
36 fn client_id(&self) -> Option<&ClientId> {
37 Some(&self.client_id)
38 }
39
40 fn client_secret(&self) -> Option<&ClientSecret> {
41 Some(&self.client_secret)
42 }
43
44 fn token_endpoint_url(&self) -> &Url {
45 &self.token_endpoint_url
46 }
47}
48impl ProviderExtAuthorizationCodeGrant for DropboxProviderWithWebApplication {
49 fn redirect_uri(&self) -> Option<&RedirectUri> {
50 Some(&self.redirect_uri)
51 }
52
53 fn pkce_support_type(&self) -> Option<ProviderExtAuthorizationCodeGrantPkceSupportType> {
54 Some(ProviderExtAuthorizationCodeGrantPkceSupportType::Yes)
55 }
56
57 fn scopes_default(&self) -> Option<Vec<<Self as Provider>::Scope>> {
58 Some(vec![
59 DropboxScope::AccountInfoRead,
60 DropboxScope::SharingRead,
61 ])
62 }
63
64 fn authorization_endpoint_url(&self) -> &Url {
65 &self.authorization_endpoint_url
66 }
67}