Asp.Net MVC Identity 2.0을 작동시키는 법을 배우고 있습니다.OAuth 베어러 인증을위한 ASP.NET MVC ID 해설
나는 ClaimsIdentity 및 AuthenticationTicket 및 I의 소스 코드를 살펴 보았다
//This will used the HTTP header Authorization: "Bearer 1234123412341234asdfasdfasdfasdf"
OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
app.UseOAuthBearerAuthentication(OAuthBearerOptions);
Startup.Auth.cs에 대한 코드는 다음 OAuth를 무기명에 대한
[HttpGet]
[ActionName("Authenticate")]
[AllowAnonymous]
public String Authenticate(string user, string password)
{
if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password))
{
return "Failed";
}
var userIdentity = UserManager.FindAsync(user, password).Result;
if (userIdentity != null)
{
if (User.Identity.IsAuthenticated)
{
return "Already authenticated!";
}
var identity = new ClaimsIdentity(Startup.OAuthBearerOptions.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, user));
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userIdentity.Id));
AuthenticationTicket ticket = new AuthenticationTicket(identity, new AuthenticationProperties());
var currentUtc = new SystemClock().UtcNow;
ticket.Properties.IssuedUtc = currentUtc;
ticket.Properties.ExpiresUtc = currentUtc.Add(TimeSpan.FromMinutes(1));
string AccessToken = Startup.OAuthBearerOptions.AccessTokenFormat.Protect(ticket);
return AccessToken;
}
return "Failed in the end";
}
작동이 코드가 티켓이 신원에 어떻게 등록되어 있는지 보지 마십시오.
제 질문은이 티켓이 Owin 파이프 라인에 어떻게 등록 되었습니까?
가능한 경우이 티켓을 취소하는 것이 목표입니다.
미리 감사드립니다.
답장을 보내 주셔서 감사합니다. 네, 타이세이의 튜토리얼을 공부했는데 아주 좋습니다. 내가 게시 한 코드도 똑같이 작동합니다. 내가 티켓을 취소 할 수있는 방법이 있는지 알고 싶습니다. – superfly71
@ superfly71 게시물을 업데이트했습니다. 원하는 것을 성취하기 위해 새로 고침 토큰을 구현해야한다고 생각합니다. – BBauer42
내가 제공 한 링크에서 언급 한 블랙리스트 접근 방식을 실제로 채택했습니다. 나는 더 나은 접근법을 기대하고 있었다. 아무튼 감사 해요! – superfly71