public override async Task <ActionResult> IndexAsync(AuthorizationCodeResponseUrl authorizationCode, CancellationToken taskCancellationToken)
        {
            if (string.IsNullOrEmpty(authorizationCode.Code))
            {
                var errorResponse = new TokenErrorResponse(authorizationCode);

                return(OnTokenError(errorResponse));
            }

            var returnUrl = Request.Url.ToString();

            returnUrl = returnUrl.Substring(0, returnUrl.IndexOf("?"));

            await Flow.ExchangeCodeForTokenAsync(UserId, authorizationCode.Code, returnUrl,
                                                 taskCancellationToken);

            var success = GoogleCalendarSyncer.SyncToGoogleCalendar(this);

            if (!success)
            {
                return(Json("Token was revoked. Try again."));
            }

            return(Redirect(Url.Content("~/")));
        }
 public ActionResult SyncToGoogleCalendar()
 {
     if (string.IsNullOrWhiteSpace(GoogleOauthTokenService.OauthToken))
     {
         var redirectUri = GoogleCalendarSyncer.GetOauthTokenUri(this);
         return(Redirect(redirectUri));
     }
     else
     {
         var success = GoogleCalendarSyncer.SyncToGoogleCalendar(this);
         if (!success)
         {
             return(Json("Token was revoked. Try again."));
         }
     }
     return(Redirect("~/"));
 }