Trong ứng dụng dựa trên Apache Api của tôi, tôi có một tình huống mà tôi cần giải mã mã thông báo mang nhưng tôi không biết cách thực hiện điều này. Đây là startup.cs tôiThủ công giải mã mã thông báo OAuth trong C#
public class Startup
{
public static OAuthAuthorizationServerOptions OAuthServerOptions { get; private set; }
public static UnityContainer IoC;
public void Configuration(IAppBuilder app)
{
//Set Auth configuration
ConfigureOAuth(app);
....and other stuff
}
public void ConfigureOAuth(IAppBuilder app)
{
OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new AuthProvider(IoC.Resolve<IUserService>(), IoC.Resolve<IAppSettings>())
};
// Token Generation
app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
}
}
Trong điều khiển của tôi Im gửi token bearer như một tham số
[RoutePrefix("api/EP")]
public class EPController : MasterController
{
[HttpGet]
[AllowAnonymous]
[Route("DC")]
public async Task<HttpResponseMessage> GetDC(string token)
{
//Get the claim identity from the token here
//Startup.OAuthServerOptions...
//..and other stuff
}
}
Làm thế nào để tự giải mã và nhận được khiếu nại từ các dấu hiệu thông qua như là một tham số?
LƯU Ý: Tôi biết tôi có thể gửi mã thông báo trong tiêu đề và sử dụng [Duyệt] và (ClaimsIdentity) User.Identity vv nhưng câu hỏi là làm thế nào để đọc các dấu hiệu khi nó không được thể hiện trong tiêu đề.
Cảm ơn, Chỉ những gì tôi đang tìm kiếm! Tuyệt vời –
Mặc dù ở trên có thể hoạt động. Bạn có thể tìm thấy một giải pháp đơn giản hơn tại https://long2know.com/2015/05/decrypting-owin-authentication-ticket/ –