Ejemplo n.º 1
0
        private void ParseClaims(AuthenticationResult authenticationResult, OAuthAuthenticationParameters parameters)
        {
            var claims = new UserClaims();

            claims.Contact = new ContactClaims();
            claims.Name    = new NameClaims();
            if (authenticationResult.ExtraData.ContainsKey("nickname"))
            {
                claims.Contact.Email = "";
                claims.Name.Alias    = authenticationResult.ExtraData["nickname"];
            }
            if (authenticationResult.ExtraData.ContainsKey("first_name"))
            {
                claims.Name.First = authenticationResult.ExtraData["first_name"];
            }
            if (authenticationResult.ExtraData.ContainsKey("last_name"))
            {
                claims.Name.Last = authenticationResult.ExtraData["last_name"];
            }

            parameters.AddClaim(claims);
        }
Ejemplo n.º 2
0
        private AuthorizeState VerifyAuthentication(string returnUrl)
        {
            var authResult = this.VkontakteApplication.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);
        }