Skip to content

Commit

Permalink
Merge pull request #5 from RyutaroYako/feature/oauth-any-state
Browse files Browse the repository at this point in the history
Add support for custom state values in OAuth URL generation
  • Loading branch information
aoyagikouhei committed Mar 25, 2024
2 parents 8dab680 + 5ca7a50 commit 2f72d64
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,20 @@ impl TwitterOauth {
}

pub fn oauth_url(&self) -> OAuthUrlResult {
self.oauth_url_with_state(None)
}

pub fn oauth_url_with_state(&self, state: Option<String>) -> OAuthUrlResult {
let (pkce_challenge, pkce_verifier) = oauth2::PkceCodeChallenge::new_random_sha256();
let csrf_token = match state {
Some(ref state_value) => CsrfToken::new(state_value.clone()),
None => CsrfToken::new_random(),
};
let (auth_url, _csrf_token) = self
.basic_client
.clone()
.set_redirect_uri(self.redirect_url.clone())
.authorize_url(CsrfToken::new_random)
.authorize_url(|| csrf_token)
.add_scopes(self.scopes.clone())
.set_pkce_challenge(pkce_challenge)
.url();
Expand Down

0 comments on commit 2f72d64

Please sign in to comment.