Make the OWIN allow cross origin

来源:互联网 发布:java编程代码 编辑:程序博客网 时间:2024/05/22 10:51
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {


            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });


            using (AuthenticationRepository _repo = new AuthenticationRepository())
            {


                AppUser user = await _repo.GetUserForEmail(context.UserName, context.Password);
                string username = string.Empty;
                if (user == null)
                {
                    user = _repo.GetUserForLoginUsingAppId(context.UserName, context.Password);
                    if (user == null)
                    {
                        context.SetError("invalid_grant", "The user name or password is incorrect.");
                        return;
                    }
                }


                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
                identity.AddClaim(new Claim(HandpickClaimTypes.UserId, user.Id.ToString()));
                context.Validated(identity);
            }
        }
0 0
原创粉丝点击