Пример #1
0
        public override ProviderCredentials CreateCredentials(ClaimsIdentity claimsIdentity)
        {
            if (claimsIdentity == null)
            {
                throw new ArgumentNullException("claimsIdentity");
            }

            string username = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier).Value;
            CustomLoginProviderCredentials credentials = new CustomLoginProviderCredentials
            {
                UserId = TokenHandler.CreateUserId(this.Name, username)
            };

            return(credentials);
        }
        public override ProviderCredentials CreateCredentials(ClaimsIdentity claimsIdentity)
        {
            if (claimsIdentity == null)
            {
                throw new ArgumentNullException("claimsIdentity");
            }

            var email  = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier).Value;
            var userId = TokenHandler.CreateUserId(Name, email);
            //
            //User user = context.Users.SingleOrDefault(u => u.Email == email);
            var credentials = new StandartLoginProviderCredentials
            {
                UserId = userId
            };

            return(credentials);
        }
Пример #3
0
        /// <summary>
        /// </summary>
        /// <param name="claimsIdentity"></param>
        /// <returns></returns>
        public override ProviderCredentials CreateCredentials(
            ClaimsIdentity claimsIdentity)
        {
            try
            {
                var providerAccessToken = claimsIdentity
                                          .FindFirst(ServiceClaimTypes.ProviderAccessToken);
                if (providerAccessToken == null)
                {
                    return(null);
                }
                var name = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
                if (name == null)
                {
                    return(null);
                }
                var userId = TokenHandler.CreateUserId(Name, name?.Value);
                if (userId == null)
                {
                    return(null);
                }
                var emailClaim = claimsIdentity.FindFirst(ClaimTypes.Email);
                var nameClaim  = claimsIdentity.FindFirst(ClaimTypes.Name);

                var credentials = new VKCredentials
                {
                    UserId      = userId,
                    AccessToken = providerAccessToken?.Value
                };
                AuthUtils.CreateAccount(new ApartmenthostContext(), Name, name?.Value, userId, emailClaim?.Value,
                                        nameClaim?.Value);
                return(credentials);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }