Ejemplo n.º 1
0
        public async Task <bool> deleteGoogleAccount(ThirdPartyAuthenticationForView modelData)
        {
            bool RetValue = false;
            ThirdPartyCalendarAuthenticationModel ThirdPartyAuth = db.ThirdPartyAuthentication.Where(obj => obj.ID == modelData.ID).Single();

            if (ThirdPartyAuth != null)
            {
                UserCredential googleCredential = ThirdPartyAuth.getGoogleOauthCredentials();
                try
                {
                    await googleCredential.RefreshTokenAsync(CancellationToken.None).ConfigureAwait(false);

                    await googleCredential.RevokeTokenAsync(CancellationToken.None).ConfigureAwait(false);

                    db.ThirdPartyAuthentication.Remove(ThirdPartyAuth);
                    RetValue = true;
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("invalid_grant"))
                    {
                        db.ThirdPartyAuthentication.Remove(ThirdPartyAuth);
                    }
                    else
                    {
                        throw e;
                    }
                }
                //await ThirdPartyAuth.getGoogleOauthCredentials().RevokeTokenAsync(CancellationToken.None).ConfigureAwait(false);

                await db.SaveChangesAsync().ConfigureAwait(false);
            }

            return(RetValue);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> deleteGoogleAccount(ThirdPartyAuthenticationForView modelData)
        {
            ThirdPartyCalendarAuthenticationModelsController thirdPartyController = new ThirdPartyCalendarAuthenticationModelsController();
            await thirdPartyController.deleteGoogleAccount(modelData).ConfigureAwait(false);

            return(RedirectToAction("ImportCalendar"));
        }