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);
            }
        }
Exemple #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"
                    );
            }
        }
 public async Task <User> GetById(Guid userId)
 {
     return(await _mongo.GetUser(userId));
 }