diff --git a/src/auth.rs b/src/auth.rs index 41a6e774..bcbfb1f8 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -45,6 +45,8 @@ pub enum Auth { App(AppAuth), /// Authenticate as a Github OAuth App OAuth(OAuth), + /// Authenticate using a User Access Token + UserAccessToken(SecretString), } impl Default for Auth { diff --git a/src/lib.rs b/src/lib.rs index eac25d4d..5660ff38 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -489,6 +489,12 @@ impl OctocrabBuilder self } + /// Authenticate with a user access token. + pub fn user_access_token(mut self, token: String) -> Self { + self.config.auth = Auth::UserAccessToken(SecretString::new(token)); + self + } + /// Set the base url for `Octocrab`. pub fn base_uri(mut self, base_uri: impl TryInto) -> Result { self.config.base_uri = Some( @@ -624,6 +630,13 @@ impl OctocrabBuilder )); AuthState::None } + Auth::UserAccessToken(token) => { + hmap.push(( + http::header::AUTHORIZATION, + format!("Bearer {}", token.expose_secret()).parse().unwrap(), + )); + AuthState::None + } Auth::App(app_auth) => AuthState::App(app_auth), Auth::OAuth(device) => { hmap.push((