2017-05-24 18 views
0

나는 나중에 사용하기 위해 데이터베이스에 저장 한 generate refresh token에 다음 코드를 구현했습니다. 내가 validate the use privileges without using asp.net identity 원하는토큰을 생성하는 Oauth가 구현되었지만 해당 사용자의 액세스 권한을 확인하는 방법은 특정 방법이 아닐까요?

public class SimpleRefreshTokenProvider : IAuthenticationTokenProvider 
{ 
    public async Task CreateAsync(AuthenticationTokenCreateContext context) 
    { 
     var clientid = context.Ticket.Properties.Dictionary["as:client_id"]; 

     if (string.IsNullOrEmpty(clientid)) 
     { 
      return; 
     } 

     var refreshTokenId = Guid.NewGuid().ToString("n"); 

     using (AuthRepository _repo = new AuthRepository()) 
     { 
      var refreshTokenLifeTime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime"); 

      var token = new RefreshToken() 
      { 
       Id = Helper.GetHash(refreshTokenId), 
       ClientId = clientid, 
       Subject = context.Ticket.Identity.Name, 
       IssuedUtc = DateTime.UtcNow, 
       ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime)) 
      }; 

      context.Ticket.Properties.IssuedUtc = token.IssuedUtc; 
      context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc; 

      token.ProtectedTicket = context.SerializeTicket(); 

      var result = await _repo.AddRefreshToken(token); 

      if (result) 
      { 
       context.SetToken(refreshTokenId); 
      }   
     } 
    } 
} 

,

나는 나의 custom tables of user and privileges 있습니다.

사용자가 의 모든 webapi 메소드에 액세스 할 수있는 권한이 있는지 또는 데이터베이스에서만 선택되었는지 여부를 어떻게 확인할 수 있습니까?

답변

2

당신은 AuthorizeAttribute

public class OwnAuthorizeAttribute : AuthorizeAttribute 
{ 
    public override void OnAuthorization(AuthorizationContext filterContext) 
    { 
     // Your auth code 

     // If you need base functionality 
     base.OnAuthorization(filterContext); 
    } 
} 

에서 상속 할 수 있습니다 또는 당신은 Action Filters

에 따라 자신의 메커니즘을 구현 시도 할 수 있습니다