mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-02-23 15:50:00 +01:00
Make rustls dependency optional by introducing "service_account" feature
Now, service_account code must be (implicitly) enabled. Asked for in feature #168
This commit is contained in:
@@ -7,6 +7,8 @@ use crate::device::DeviceFlow;
|
||||
use crate::error::Error;
|
||||
use crate::installed::{InstalledFlow, InstalledFlowReturnMethod};
|
||||
use crate::refresh::RefreshFlow;
|
||||
|
||||
#[cfg(feature = "service_account")]
|
||||
use crate::service_account::{ServiceAccountFlow, ServiceAccountFlowOpts, ServiceAccountKey};
|
||||
use crate::storage::{self, Storage, TokenStorage};
|
||||
use crate::types::{AccessToken, ApplicationSecret, TokenInfo};
|
||||
@@ -242,7 +244,10 @@ impl DeviceFlowAuthenticator {
|
||||
/// .expect("failed to create authenticator");
|
||||
/// # }
|
||||
/// ```
|
||||
#[cfg(feature = "service_account")]
|
||||
pub struct ServiceAccountAuthenticator;
|
||||
|
||||
#[cfg(feature = "service_account")]
|
||||
impl ServiceAccountAuthenticator {
|
||||
/// Use the builder pattern to create an Authenticator that uses a service account.
|
||||
#[cfg(any(feature = "hyper-rustls", feature = "hyper-tls"))]
|
||||
@@ -549,6 +554,7 @@ impl<C> AuthenticatorBuilder<C, InstalledFlow> {
|
||||
/// .expect("failed to create authenticator");
|
||||
/// # }
|
||||
/// ```
|
||||
#[cfg(feature = "service_account")]
|
||||
impl<C> AuthenticatorBuilder<C, ServiceAccountFlowOpts> {
|
||||
/// Use the provided subject.
|
||||
pub fn subject(self, subject: impl Into<String>) -> Self {
|
||||
@@ -598,12 +604,14 @@ mod private {
|
||||
use crate::device::DeviceFlow;
|
||||
use crate::error::Error;
|
||||
use crate::installed::InstalledFlow;
|
||||
#[cfg(feature = "service_account")]
|
||||
use crate::service_account::ServiceAccountFlow;
|
||||
use crate::types::{ApplicationSecret, TokenInfo};
|
||||
|
||||
pub enum AuthFlow {
|
||||
DeviceFlow(DeviceFlow),
|
||||
InstalledFlow(InstalledFlow),
|
||||
#[cfg(feature = "service_account")]
|
||||
ServiceAccountFlow(ServiceAccountFlow),
|
||||
ApplicationDefaultCredentialsFlow(ApplicationDefaultCredentialsFlow),
|
||||
}
|
||||
@@ -613,6 +621,7 @@ mod private {
|
||||
match self {
|
||||
AuthFlow::DeviceFlow(device_flow) => Some(&device_flow.app_secret),
|
||||
AuthFlow::InstalledFlow(installed_flow) => Some(&installed_flow.app_secret),
|
||||
#[cfg(feature = "service_account")]
|
||||
AuthFlow::ServiceAccountFlow(_) => None,
|
||||
AuthFlow::ApplicationDefaultCredentialsFlow(_) => None,
|
||||
}
|
||||
@@ -632,6 +641,7 @@ mod private {
|
||||
AuthFlow::InstalledFlow(installed_flow) => {
|
||||
installed_flow.token(hyper_client, scopes).await
|
||||
}
|
||||
#[cfg(feature = "service_account")]
|
||||
AuthFlow::ServiceAccountFlow(service_account_flow) => {
|
||||
service_account_flow.token(hyper_client, scopes).await
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// Copyright (c) 2016 Google Inc (lewinb@google.com).
|
||||
//
|
||||
// Refer to the project root for licensing information.
|
||||
#[cfg(feature = "service_account")]
|
||||
use crate::service_account::ServiceAccountKey;
|
||||
use crate::types::{ApplicationSecret, ConsoleApplicationSecret};
|
||||
|
||||
@@ -39,6 +40,7 @@ pub fn parse_application_secret<S: AsRef<[u8]>>(secret: S) -> io::Result<Applica
|
||||
|
||||
/// Read a service account key from a JSON file. You can download the JSON keys from the Google
|
||||
/// Cloud Console or the respective console of your service provider.
|
||||
#[cfg(feature = "service_account")]
|
||||
pub async fn read_service_account_key<P: AsRef<Path>>(path: P) -> io::Result<ServiceAccountKey> {
|
||||
let key = tokio::fs::read(path).await?;
|
||||
parse_service_account_key(key)
|
||||
|
||||
@@ -80,6 +80,8 @@ pub mod error;
|
||||
mod helper;
|
||||
mod installed;
|
||||
mod refresh;
|
||||
|
||||
#[cfg(feature = "service_account")]
|
||||
mod service_account;
|
||||
|
||||
/// Interface for storing tokens so that they can be re-used. There are built-in memory and
|
||||
@@ -91,13 +93,16 @@ mod types;
|
||||
#[doc(inline)]
|
||||
pub use crate::authenticator::{
|
||||
ApplicationDefaultCredentialsAuthenticator, DeviceFlowAuthenticator,
|
||||
InstalledFlowAuthenticator, ServiceAccountAuthenticator,
|
||||
InstalledFlowAuthenticator
|
||||
};
|
||||
#[cfg(feature = "service_account")]
|
||||
pub use crate::authenticator::ServiceAccountAuthenticator;
|
||||
|
||||
pub use crate::helper::*;
|
||||
pub use crate::installed::InstalledFlowReturnMethod;
|
||||
|
||||
pub use crate::application_default_credentials::ApplicationDefaultCredentialsFlowOpts;
|
||||
#[cfg(feature = "service_account")]
|
||||
pub use crate::service_account::ServiceAccountKey;
|
||||
|
||||
#[doc(inline)]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![cfg(feature = "service_account")]
|
||||
|
||||
//! This module provides a flow that obtains tokens for service accounts.
|
||||
//!
|
||||
//! Service accounts are usually used by software (i.e., non-human actors) to get access to
|
||||
|
||||
Reference in New Issue
Block a user