private void ParseClaims(AuthenticationResult authenticationResult, OAuthAuthenticationParameters parameters)
        {
            var claims = new UserClaims();

            claims.Name = new NameClaims();
            if (authenticationResult.ExtraData.ContainsKey("id"))
            {
                claims.Name.Alias = authenticationResult.ExtraData["id"];
            }
            if (authenticationResult.ExtraData.ContainsKey("nickname"))
            {
                claims.Name.Nickname = authenticationResult.ExtraData["nickname"];
                claims.Name.First    = claims.Name.Nickname;
            }

            parameters.AddClaim(claims);
        }
        private AuthorizeState VerifyAuthentication(string returnUrl)
        {
            var authResult = this.WeixinApplication.VerifyAuthentication(
                _httpContext, GenerateLocalCallbackUri(returnUrl));

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

                if (!authResult.ExtraData.ContainsKey("accesstoken"))
                {
                    throw new NopException("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);
        }