/// <summary> /// Adds firebase authentication to the service collection using an access token for the key /// </summary> /// <param name="services">IServiceCollection instance to which you will be adding the auth policy</param> /// <param name="accessToken">The access token to use for the credential</param> /// <param name="accessMethod"> /// Optional. The Google.Apis.Auth.OAuth2.IAccessMethod to use within /// this credential. If null, will default to Google.Apis.Auth.OAuth2.BearerToken.AuthorizationHeaderAccessMethod. /// </param> public static void AddFirebaseAdminFromAccessToken( this IServiceCollection services, string accessToken, IAccessMethod accessMethod = null) { AddAuthPolicy(services); CreateApp(GoogleCredential.FromAccessToken(accessToken, accessMethod)); }
public TokenNegotiator( TokenNegotiatorOptions options, IAccessMethod accessMethod, ITokenValidator validator, ITokenStore store) { AccessMethod = accessMethod; TokenStore = store; Validator = validator; _options = options; }
/// <summary>Constructs a new flow using the initializer's properties.</summary> public AuthorizationCodeFlow(Initializer initializer) { clientSecrets = initializer.ClientSecrets; if (clientSecrets == null) { if (initializer.ClientSecretsStream == null) { throw new ArgumentException("You MUST set ClientSecret or ClientSecretStream on the initializer"); } using (initializer.ClientSecretsStream) { clientSecrets = GoogleClientSecrets.FromStream(initializer.ClientSecretsStream).Secrets; } } else if (initializer.ClientSecretsStream != null) { throw new ArgumentException( "You CAN'T set both ClientSecrets AND ClientSecretStream on the initializer"); } accessMethod = initializer.AccessMethod.ThrowIfNull("Initializer.AccessMethod"); clock = initializer.Clock.ThrowIfNull("Initializer.Clock"); tokenServerUrl = initializer.TokenServerUrl.ThrowIfNullOrEmpty("Initializer.TokenServerUrl"); authorizationServerUrl = initializer.AuthorizationServerUrl.ThrowIfNullOrEmpty ("Initializer.AuthorizationServerUrl"); dataStore = initializer.DataStore; if (dataStore == null) { Logger.Warning("Datastore is null, as a result the user's credential will not be stored"); } scopes = initializer.Scopes; // Set the HTTP client. DefaultExponentialBackOffPolicy = initializer.DefaultExponentialBackOffPolicy; HttpClientFactory = initializer.HttpClientFactory ?? new HttpClientFactory(); var httpArgs = new CreateHttpClientArgs(); // Add exponential back-off initializer if necessary. if (DefaultExponentialBackOffPolicy != ExponentialBackOffPolicy.None) { httpArgs.Initializers.Add(new ExponentialBackOffInitializer( DefaultExponentialBackOffPolicy, () => new BackOffHandler(new ExponentialBackOff()))); } httpClient = HttpClientFactory.CreateHttpClient(httpArgs); }
/// <summary>Constructs a new service account credential using the given initializer.</summary> public ServiceCredential(Initializer initializer) { tokenServerUrl = initializer.TokenServerUrl; accessMethod = initializer.AccessMethod.ThrowIfNull("initializer.AccessMethod"); clock = initializer.Clock.ThrowIfNull("initializer.Clock"); // Set the HTTP client. var httpArgs = new CreateHttpClientArgs(); // Add exponential back-off initializer if necessary. if (initializer.DefaultExponentialBackOffPolicy != ExponentialBackOffPolicy.None) { httpArgs.Initializers.Add( new ExponentialBackOffInitializer(initializer.DefaultExponentialBackOffPolicy, () => new BackOffHandler(new ExponentialBackOff()))); } httpClient = (initializer.HttpClientFactory ?? new HttpClientFactory()).CreateHttpClient(httpArgs); }
public AccessTokenCredential(string accessToken, IAccessMethod accessMethod, string quotaProject = null) { _accessToken = accessToken; _accessMethod = accessMethod; QuotaProject = quotaProject; }
public AccessTokenCredential(string accessToken, IAccessMethod accessMethod) { _accessToken = accessToken; _accessMethod = accessMethod; }
/// <summary>Constructs a new flow using the initializer's properties.</summary> public AuthorizationCodeFlow(Initializer initializer) { clientSecrets = initializer.ClientSecrets; if (clientSecrets == null) { if (initializer.ClientSecretsStream == null) { throw new ArgumentException("You MUST set ClientSecret or ClientSecretStream on the initializer"); } using (initializer.ClientSecretsStream) { clientSecrets = GoogleClientSecrets.Load(initializer.ClientSecretsStream).Secrets; } } else if (initializer.ClientSecretsStream != null) { throw new ArgumentException( "You CAN'T set both ClientSecrets AND ClientSecretStream on the initializer"); } accessMethod = initializer.AccessMethod.ThrowIfNull("Initializer.AccessMethod"); clock = initializer.Clock.ThrowIfNull("Initializer.Clock"); tokenServerUrl = initializer.TokenServerUrl.ThrowIfNullOrEmpty("Initializer.TokenServerUrl"); authorizationServerUrl = initializer.AuthorizationServerUrl.ThrowIfNullOrEmpty ("Initializer.AuthorizationServerUrl"); dataStore = initializer.DataStore; if (dataStore == null) { Logger.Warning("Datastore is null, as a result the user's credential will not be stored"); } scopes = initializer.Scopes; // Set the HTTP client. var httpArgs = new CreateHttpClientArgs(); // Add exponential back-off initializer if necessary. if (initializer.DefaultExponentialBackOffPolicy != ExponentialBackOffPolicy.None) { httpArgs.Initializers.Add( new ExponentialBackOffInitializer(initializer.DefaultExponentialBackOffPolicy, () => new BackOffHandler(new ExponentialBackOff()))); } httpClient = (initializer.HttpClientFactory ?? new HttpClientFactory()).CreateHttpClient(httpArgs); }
/// <summary> /// Create a <see cref="GoogleCredential"/> directly from the provided access token. /// The access token will not be automatically refreshed. /// </summary> /// <param name="accessToken">The access token to use within this credential.</param> /// <param name="accessMethod">Optional. The <see cref="IAccessMethod"/> to use within this credential. /// If <c>null</c>, will default to <see cref="BearerToken.AuthorizationHeaderAccessMethod"/>.</param> /// <returns>A credential based on the provided access token.</returns> public static GoogleCredential FromAccessToken(string accessToken, IAccessMethod accessMethod = null) { accessMethod = accessMethod ?? new BearerToken.AuthorizationHeaderAccessMethod(); return(new GoogleCredential(new AccessTokenCredential(accessToken, accessMethod))); }
public RequestInterceptorCredentialWrapper(string accessToken, IAccessMethod accessMethod) =>
protected AccessMethod(string name, IAccessMethod method) { Name = name; Method = method; }