Example #1
0
        public async Task <bool> RemoveConfig(string userId, string configId)
        {
            var config = await repository.GetConfiguration(configId);

            if (config.Type == CalendarType.Google)
            {
                var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer()
                {
                    ClientSecrets = new Google.Apis.Auth.OAuth2.ClientSecrets()
                    {
                        ClientId     = options.GoogleClientID,
                        ClientSecret = options.GoogleClientSecret
                    },
                    Scopes = new[] { "https://www.googleapis.com/auth/calendar.events.readonly",
                                     "https://www.googleapis.com/auth/calendar.readonly" },
                    RevokeTokenUrl = "https://accounts.google.com/o/oauth2/revoke"
                });
                try
                {
                    await flow.RevokeTokenAsync(null, config.AccessToken, CancellationToken.None);
                }
                catch (Exception e)
                {
                    logger.LogError("Could not revoke access token.", e);
                    try
                    {
                        await flow.RevokeTokenAsync(null, config.RefreshToken, CancellationToken.None);
                    }
                    catch (Exception e2)
                    {
                        logger.LogError("Could not revoke refresh token.", e2);
                    }
                }
            }
            return(await repository.RemoveConfig(userId, configId));
        }
Example #2
0
        public async Task RevokeFakeToken_BadRequest()
        {
            // Tests that the correct 400 response is received from the server, given an invalid token.
            // Validates the revoke URL and verb are correct.
            using (var f = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecretsStream = Helper.GetClientSecretStream()
            }))
            {
                var ex = await Assert.ThrowsAsync <TokenResponseException>(
                    () => f.RevokeTokenAsync("fake-user", "fake-token", default));

                Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode);
                Assert.Equal("invalid_token", ex.Error.Error);
            }
        }