내 자신의 사용자 지정 WebApi 인증을 구현하고 싶습니다. ApplicationOAuthProvider에서 GrantResourceOwnerCredentials 메서드를 수정하려고합니다. 인증과 거짓 인증되지 않은 위해에 대한 true를 돌려 내 웹 서비스 호출웹 API 2 OWIN 무기명 토큰 사용자 지정 인증
IdentityUser user = await userManager.FindAsync(context.UserName, context.Password);
:
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
using (UserManager<IdentityUser> userManager = _userManagerFactory())
{
IdentityUser user = await userManager.FindAsync(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
ClaimsIdentity oAuthIdentity = await userManager.CreateIdentityAsync(user,
context.Options.AuthenticationType);
ClaimsIdentity cookiesIdentity = await userManager.CreateIdentityAsync(user,
CookieAuthenticationDefaults.AuthenticationType);
AuthenticationProperties properties = CreateProperties(user.UserName);
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
context.Validated(ticket);
context.Request.Context.Authentication.SignIn(cookiesIdentity);
}
}
나는 인증을 교체합니다.
if (authenticated)
{
IdentityUser user = new IdentityUser("username");
}
그러나 ClaimsIdentity를 진행하는 방법을 모르겠습니다. 누구나 참조 할 수있는 샘플이 있습니까? 감사.