oauth2_linkedin/
authorization_code_grant.rs

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