1
0
Fork 0

add oauth2 authentication

This commit is contained in:
Cyborus 2024-05-22 16:52:34 -04:00
parent bf8d6e1a3b
commit 119571229c
No known key found for this signature in database

View file

@ -57,6 +57,12 @@ pub enum Auth<'a> {
/// To learn about token scope, see /// To learn about token scope, see
/// [the official Forgejo docs](https://forgejo.org/docs/latest/user/token-scope/). /// [the official Forgejo docs](https://forgejo.org/docs/latest/user/token-scope/).
Token(&'a str), 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 /// Username, password, and 2-factor auth code (if enabled). Grants full
/// access to the user's account. /// access to the user's account.
Password { Password {
@ -124,6 +130,13 @@ impl Forgejo {
headers.insert("X-FORGEJO-OTP", key_header); 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 => (), Auth::None => (),
} }
let client = Client::builder() let client = Client::builder()