From d5a895b47fb6346785305a0766767c6f81b5440e Mon Sep 17 00:00:00 2001 From: Luke Swithenbank Date: Mon, 22 May 2023 18:22:31 +1000 Subject: [PATCH 1/2] add useraccess authentication --- src/auth.rs | 2 ++ src/lib.rs | 7 +++++++ 2 files changed, 9 insertions(+) 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..27de8ca7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -624,6 +624,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(( From f48ee3ea835e31cc65d1e29631c1eb6af69b7742 Mon Sep 17 00:00:00 2001 From: Luke Swithenbank Date: Mon, 22 May 2023 18:29:44 +1000 Subject: [PATCH 2/2] add a user_access_token method --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 27de8ca7..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(