/// <summary> /// Requests a new token as specified in /// https://developers.google.com/accounts/docs/OAuth2ServiceAccount#makingrequest. /// </summary> /// <param name="taskCancellationToken">Cancellation token to cancel operation.</param> /// <returns><c>true</c> if a new token was received successfully.</returns> public override async Task<bool> RequestAccessTokenAsync(CancellationToken taskCancellationToken) { string serializedHeader = CreateSerializedHeader(); string serializedPayload = GetSerializedPayload(); StringBuilder assertion = new StringBuilder(); assertion.Append(UrlSafeBase64Encode(serializedHeader)) .Append(".") .Append(UrlSafeBase64Encode(serializedPayload)); // Sign the header and the payload. var signature = UrlSafeBase64Encode(key.SignData(Encoding.ASCII.GetBytes(assertion.ToString()), "SHA256")); assertion.Append(".").Append(signature); // Create the request. var request = new GoogleAssertionTokenRequest() { Assertion = assertion.ToString() }; Logger.Debug("Request a new access token. Assertion data is: " + request.Assertion); var newToken = await request.ExecuteAsync(HttpClient, TokenServerUrl, taskCancellationToken, Clock) .ConfigureAwait(false); Token = newToken; return true; }
/// <summary> /// Requests a new token as specified in /// https://developers.google.com/accounts/docs/OAuth2ServiceAccount#makingrequest. /// </summary> /// <param name="taskCancellationToken">Cancellation token to cancel operation.</param> /// <returns><c>true</c> if a new token was received successfully.</returns> public override async Task<bool> RequestAccessTokenAsync(CancellationToken taskCancellationToken) { // Create the request. var request = new GoogleAssertionTokenRequest() { Assertion = CreateAssertionFromPayload(CreatePayload()) }; Logger.Debug("Request a new access token. Assertion data is: " + request.Assertion); var newToken = await request.ExecuteAsync(HttpClient, TokenServerUrl, taskCancellationToken, Clock) .ConfigureAwait(false); Token = newToken; return true; }