コード例 #1
0
        public static string Generate(AuthUserQueryResponse user)
        {
            var clains = new Dictionary <string, string>();

            user.Interfaces.ForEach(o =>
            {
                var interfaceSplit = o.Split(";");
                clains.Add(interfaceSplit[0], interfaceSplit[1]);
            });
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(Environment.GetEnvironmentVariable("secretJwt"));
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim("userId", user.IdUsuario.ToString()),
                }),
                Expires = DateTime.UtcNow.AddMinutes(5),
                Claims  = new Dictionary <string, object>()
                {
                    { "interfaces", clains }
                },
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            return(tokenHandler.WriteToken(token));
        }
コード例 #2
0
        public AuthUserQueryResponse SearchUserByEmail
            (string email)
        {
            var result =
                new AuthUserQueryResponse {
                Condition = false, Message = string.Empty, User = new UserQueryModel()
            };

            try
            {
                var user = _userManager.Users.SingleOrDefault(i => i.Email == email);
                if (user == null)
                {
                    return(result);
                }
                result.Condition           = true;
                result.User.user_id        = user.Id;
                result.User.email          = user.Email;
                result.User.email_verified = user.EmailConfirmed;
                return(result);
            }
            catch (ArgumentNullException e)
            {
                result.Condition = false;
                result.Message   = e.Message;
                return(result);
            }
        }
コード例 #3
0
        public AuthUserQueryResponse SearchUserByEmail
            (string email)
        {
            var result = new AuthUserQueryResponse {
                Condition = false, Message = string.Empty, User = new UserQueryModel()
            };
            //var emailEncoded = System.Net.WebUtility.UrlEncode(email);
            var url         = $"{_applicationSetting.Authority}api/v2/users-by-email?email={email}";
            var tokenResult = GetManagementApiToken();

            var httpResult = _httpService.Get(url, tokenResult.token);

            if (!httpResult.condition)
            {
                _logService.Log(LogLevel.Exception, $"(bool condition, string message, UserQueryModel value)  SearchUserByEmail -> there was a issue getting the details from auth0");
                result.Message = "There was a issue getting the user information.";
                return(result);
            }
            try
            {
                var deserializedResult = JsonConvert.DeserializeObject <List <UserQueryModel> > (httpResult.result);
                result.Condition = true;
                result.User      = deserializedResult.First();
                return(result);
            }
            catch (Exception e)
            {
                _logService.Log(LogLevel.Exception, e.Message);
                result.Message = e.Message;
                return(result);
            }
        }