private AuthorizeState VerifyAuthentication(string returnUrl)
        {
            var authResult = this.FacebookApplication.VerifyAuthentication(_httpContext, GenerateLocalCallbackUri());

            if (authResult.IsSuccessful)
            {
                if (!authResult.ExtraData.ContainsKey("id"))
                    throw new Exception("Authentication result does not contain id data");

                if (!authResult.ExtraData.ContainsKey("accesstoken"))
                    throw new Exception("Authentication result does not contain accesstoken data");

                var parameters = new OAuthAuthenticationParameters(Provider.SystemName)
                {
                    ExternalIdentifier = authResult.ProviderUserId,
                    OAuthToken = authResult.ExtraData["accesstoken"],
                    OAuthAccessToken = authResult.ProviderUserId,
                };

                if (_externalAuthenticationSettings.AutoRegisterEnabled)
                    ParseClaims(authResult, parameters);

                var result = _authorizer.Authorize(parameters);

                return new AuthorizeState(returnUrl, result);
            }

            var state = new AuthorizeState(returnUrl, OpenAuthenticationStatus.Error);
            var error = authResult.Error != null ? authResult.Error.Message : "Unknown error";
            state.AddError(error);
            return state;
        }
        private AuthorizeState RequestAuthentication(string returnUrl)
        {
            var identifier = new OpenIdIdentifier(EnternalIdentifier);
            if (!identifier.IsValid)
            {
                var result = new AuthorizeState(returnUrl, OpenAuthenticationStatus.Error);
                result.AddError("Invalid Open ID identifier");
                return result;
            }

            try
            {
                var request = _openIdRelyingPartyService.CreateRequest(identifier);

                request.AddExtension(Claims.CreateClaimsRequest());
                request.AddExtension(Claims.CreateFetchRequest());

                return new AuthorizeState(returnUrl, OpenAuthenticationStatus.RequiresRedirect)
                {
                    Result = request.RedirectingResponse.AsActionResultMvc5()
                };
            }
            catch (ProtocolException ex)
            {
                var result = new AuthorizeState(returnUrl, OpenAuthenticationStatus.Error);
                result.AddError("Unable to authenticate: " + ex.Message);
                return result;
            }
        }
 private AuthorizeState VerifyAuthentication(string returnUrl)
 {
     switch (_openIdRelyingPartyService.Response.Status)
     {
         case AuthenticationStatus.Authenticated:
             var parameters = new OpenIdAuthenticationParameters(_openIdRelyingPartyService.Response);
             return new AuthorizeState(returnUrl, _authorizer.Authorize(parameters));
         case AuthenticationStatus.Canceled:
             {
                 var result = new AuthorizeState(returnUrl, OpenAuthenticationStatus.AssociateOnLogon);
                 return result;
             }
         case AuthenticationStatus.Failed:
             {
                 var result = new AuthorizeState(returnUrl, OpenAuthenticationStatus.Error);
                 result.AddError(_openIdRelyingPartyService.Response.Exception.Message);
                 return result;
             }
     }
     return new AuthorizeState(returnUrl, OpenAuthenticationStatus.Unknown);
 }
        private AuthorizeState TranslateResponseState(string returnUrl, FacebookOAuthResult oAuthResult)
        {
            if (oAuthResult.IsSuccess)
            {
                var parameters = new OAuthAuthenticationParameters(Provider.SystemName)
                {
                    ExternalIdentifier = GetAccessToken(oAuthResult.Code),
                    OAuthToken = oAuthResult.Code,
                    OAuthAccessToken = GetAccessToken(oAuthResult.Code)
                };

                if (_externalAuthenticationSettings.AutoRegisterEnabled)
                    GetClaims(parameters);

                var result = _authorizer.Authorize(parameters);

                return new AuthorizeState(returnUrl, result);
            }

            var state = new AuthorizeState(returnUrl, OpenAuthenticationStatus.Error);
            state.AddError(string.Format("Reason: {0}, Description: {1}", oAuthResult.ErrorReason, oAuthResult.ErrorDescription));
            return state;
        }