public void Constructor_InvalidSourceCredential() { var sourceCredential = GoogleCredential.FromComputeCredential(); var options = new ImpersonationOptions("principal", null, null, null); var initializer = new ImpersonatedCredential.Initializer(sourceCredential, options); var ex = Assert.Throws <InvalidOperationException>(() => new ImpersonatedCredential(initializer)); Assert.Equal("The underlying credential of source credential must be UserCredential or ServiceAccountCredential.", ex.Message); }
public override GoogleCredential CreateScoped(IEnumerable <string> scopes) { var impersonatedCredential = credential as ImpersonatedCredential; var initializer = new ImpersonatedCredential.Initializer(impersonatedCredential) { Options = impersonatedCredential.Options.WithScopes(scopes) }; return(new ImpersonatedGoogleCredential(new ImpersonatedCredential(initializer))); }
private static ImpersonatedCredential CreateImpersonatedCredentialForBody(object body, bool serializeBody = true, HttpStatusCode status = HttpStatusCode.OK) { var sourceCredential = CreateSourceCredential(); var content = ""; if (serializeBody) { content = NewtonsoftJsonSerializer.Instance.Serialize(body); } else { content = (string)body; } var messageHandler = new FakeHttpMessageHandler(status, content); var options = new ImpersonationOptions("principal", null, null, new[] { "scope" }); var initializer = new ImpersonatedCredential.Initializer(sourceCredential, options) { Clock = _clock, HttpClientFactory = new MockHttpClientFactory(messageHandler) }; return(new ImpersonatedCredential(initializer)); }