Beispiel #1
0
        public ActionResult CheckAuthorizationStatus(string provider, int userId)
        {
            OAuthAuthorizationResult result = null;
            OAuthClient client = OAuthClient.GetClient(provider);

            if (client != null)
            {
                result = client.CheckAuthorizationStatus(userId);
            }

            return(Json(result));
        }
        /// <summary>
        /// Occurs when user gets authorized.
        /// </summary>
        /// <param name="userId">User Id.</param>
        /// <param name="result">Result.</param>
        /// <returns>Result.</returns>
        protected override OAuthAuthorizationResult OnAuthorized(int userId, OAuthAuthorizationResult result)
        {
            OAuthAuthorizationResult ret = result;
            string ping = "https://www.googleapis.com/analytics/v3/data/ga";

            if (!OAuthWebClient.CheckAuthorized(ping, result.AccessToken))
            {
                ret = EnsureAuthorization(userId, true);

                if (ret == null || string.IsNullOrEmpty(ret.AccessToken) ||
                    !OAuthWebClient.CheckAuthorized(ping, ret.AccessToken))
                {
                    ret.Authorized  = false;
                    ret.AccessToken = string.Empty;
                }
            }

            return(ret);
        }