Ejemplo n.º 1
0
        public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            try
            {
                if (!Utils.IsNullOrEmpty(context.Subject.Identity.Name))
                {
                    var user = await _mongoStore.GetUser(context.Subject.Identity.Name);

                    SetClaims(context, user);
                }
                else
                {
                    var username = context.Subject.Claims.FirstOrDefault(claim => claim.Type == "sub");


                    if (!Utils.IsNullOrEmpty(username.Value))
                    {
                        var user = await _mongoStore.GetUser(username.Value);

                        SetClaims(context, user);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ProfileService.GetProfileDataAsync Exception:\n" + ex);
            }
        }
Ejemplo n.º 2
0
        public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var user = await _mongoStore.GetUser(context.UserName, context.Password);

            if (user == null)
            {
                context.Result = new GrantValidationResult(
                    TokenRequestErrors.InvalidGrant,
                    "Invalid Credentials"
                    );
            }
            else
            {
                context.Result = new GrantValidationResult(
                    subject: user.Id.ToString(),
                    authenticationMethod: "custom"
                    );
            }
        }
Ejemplo n.º 3
0
 public async Task <User> GetById(Guid userId)
 {
     return(await _mongo.GetUser(userId));
 }