faucet_stream/auth/
mod.rs1pub mod api_key;
4pub mod basic;
5pub mod bearer;
6pub mod custom;
7pub mod oauth2;
8
9use crate::error::FaucetError;
10use reqwest::header::HeaderMap;
11
12#[derive(Debug, Clone)]
14pub enum Auth {
15 None,
16 Bearer(String),
17 Basic {
18 username: String,
19 password: String,
20 },
21 ApiKey {
22 header: String,
23 value: String,
24 },
25 OAuth2 {
26 token_url: String,
27 client_id: String,
28 client_secret: String,
29 scopes: Vec<String>,
30 },
31 Custom(HeaderMap),
32}
33
34impl Auth {
35 pub fn apply(&self, headers: &mut HeaderMap) -> Result<(), FaucetError> {
36 match self {
37 Auth::None => Ok(()),
38 Auth::Bearer(token) => {
39 bearer::apply(headers, token);
40 Ok(())
41 }
42 Auth::Basic { username, password } => {
43 basic::apply(headers, username, password);
44 Ok(())
45 }
46 Auth::ApiKey { header, value } => api_key::apply(headers, header, value),
47 Auth::OAuth2 { .. } => Ok(()),
48 Auth::Custom(h) => {
49 custom::apply(headers, h);
50 Ok(())
51 }
52 }
53 }
54}
55
56pub use oauth2::fetch_oauth2_token;