1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using Microsoft.AspNetCore.Mvc.Filters;
- using System.IdentityModel.Tokens.Jwt;
- namespace OASystem.API
- {
- public class OASystemAuthentication : AuthorizeAttribute
- {
- public void OnAuthorization(AuthorizationFilterContext context)
- {
- string id = context.HttpContext.User.FindFirst("id")?.Value;
- if (string.IsNullOrEmpty(id))
- {
- context.Result = new StatusCodeResult(401);
- return;
- }
- Console.WriteLine("我是Authorization过滤器");
-
-
-
- var heads = context.HttpContext.Request.Headers;
- string token = heads["Authorization"];
- token = token.Replace("Bearer ", "");
- if (string.IsNullOrEmpty(token))
- {
- Console.WriteLine("校验不通过");
- return;
- }
-
-
- var jwtHandler = new JwtSecurityTokenHandler();
- JwtSecurityToken securityToken = jwtHandler.ReadJwtToken(token);
-
-
-
-
-
-
-
- }
- }
- }
|