/// <inheritdoc/> public Task <OidcToken> GetOidcTokenAsync(OidcTokenOptions options, CancellationToken cancellationToken = default) { options.ThrowIfNull(nameof(options)); // If at some point some properties are added to OidcToken that depend on the token having been fetched // then initialize the token here. TokenRefreshManager tokenRefreshManager = null; tokenRefreshManager = new TokenRefreshManager(ct => RefreshOidcTokenAsync(tokenRefreshManager, options, ct), Clock, Logger); return(Task.FromResult(new OidcToken(tokenRefreshManager))); }
private async Task <bool> RefreshOidcTokenAsync(TokenRefreshManager caller, OidcTokenOptions oidcTokenOptions, CancellationToken cancellationToken) { var request = new ImpersonationOIdCTokenRequest { DelegateAccounts = DelegateAccounts, Audience = oidcTokenOptions.TargetAudience, IncludeEmail = true }; var oidcTokenUrl = string.Format(GoogleAuthConsts.IamIdTokenEndpointFormatString, TargetPrincipal); caller.Token = await request.ExecuteAsync(HttpClient, oidcTokenUrl, Clock, Logger, cancellationToken) .ConfigureAwait(false); return(true); }
private async Task <bool> RefreshOidcTokenAsync(TokenRefreshManager caller, OidcTokenOptions options, CancellationToken cancellationToken) { var now = Clock.UtcNow; var jwtExpiry = now + JwtLifetime; string jwtForOidc = CreateJwtAccessTokenForOidc(options, now, jwtExpiry); var req = new GoogleAssertionTokenRequest() { Assertion = jwtForOidc }; caller.Token = await req.ExecuteAsync(HttpClient, TokenServerUrl, cancellationToken, Clock).ConfigureAwait(false); return(true); }
private async Task <bool> RefreshOidcTokenAsync(TokenRefreshManager caller, OidcTokenOptions oidcTokenOptions, CancellationToken cancellationToken) { var request = new ImpersonationOIdCTokenRequest { DelegateAccounts = Options.DelegateAccounts, Audience = oidcTokenOptions.TargetAudience, IncludeEmail = true }; var body = NewtonsoftJsonSerializer.Instance.Serialize(request); var content = new StringContent(body, Encoding.UTF8, "application/json"); var oidcTokenUrl = String.Format(GoogleAuthConsts.IamIdTokenEndpointFormatString, Options.TargetPrincipal); var response = await HttpClient.PostAsync(oidcTokenUrl, content, cancellationToken).ConfigureAwait(false); caller.Token = await TokenResponse.FromHttpResponseAsync(response, Clock, Logger).ConfigureAwait(false); return(true); }
internal OidcToken(TokenRefreshManager refreshManager) =>