summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-05-22 22:52:34 +0200
committerCyborus <cyborus@cyborus.xyz>2024-05-22 22:52:34 +0200
commit119571229c18f3dc5dee5e9ed5ae76bedc310566 (patch)
tree338cc850e579250decfe0619096d7c17d6e9f391
parentadd `POST /login/oauth/access_token` (diff)
downloadforgejo-api-119571229c18f3dc5dee5e9ed5ae76bedc310566.tar.xz
forgejo-api-119571229c18f3dc5dee5e9ed5ae76bedc310566.zip
add oauth2 authentication
-rw-r--r--src/lib.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index de99450..a87a696 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -57,6 +57,12 @@ pub enum Auth<'a> {
/// To learn about token scope, see
/// [the official Forgejo docs](https://forgejo.org/docs/latest/user/token-scope/).
Token(&'a str),
+ /// OAuth2 Token. Grants full access to the user's account, except for
+ /// creating application access tokens.
+ ///
+ /// To learn how to create an OAuth2 token, see
+ /// [the official Forgejo docs on the subject](https://forgejo.org/docs/latest/user/oauth2-provider).
+ OAuth2(&'a str),
/// Username, password, and 2-factor auth code (if enabled). Grants full
/// access to the user's account.
Password {
@@ -124,6 +130,13 @@ impl Forgejo {
headers.insert("X-FORGEJO-OTP", key_header);
}
}
+ Auth::OAuth2(token) => {
+ let mut header: reqwest::header::HeaderValue = format!("Bearer {token}")
+ .try_into()
+ .map_err(|_| ForgejoError::KeyNotAscii)?;
+ header.set_sensitive(true);
+ headers.insert("Authorization", header);
+ }
Auth::None => (),
}
let client = Client::builder()