(我很抱歉在这里和github都发布了这个问题,但我真的需要帮助...)
在使用Thinktecture.IdentityModel.45进行身份验证时,我无法启用CORS(System.Web.Http.Cors).
我的令牌端点有问题,我使用的是默认的"/ token".
发生的事情是,当调用/ token(来自javascript客户端)时,浏览器发出2个调用,"OPTION"调用和"/ token"资源的"GET"调用.我正在使用一个简单的PolicyProviderFactory,以便能够检查请求是否获得正确的CORS策略,它只是返回
new EnableCorsAttribute("*", "*", "*");
Run Code Online (Sandbox Code Playgroud)
第一个OPTION调用有效,GetCorsPolicyProvider被命中.另一个调用有效,但GetCorsPolicyProvider没有被命中,结果是服务器返回200 OK,包含所有正确的标题等,但内容响应为空.
我需要在路由配置中为令牌资源添加以下内容,否则我会得到"未找到".
config.Routes.MapHttpRoute(
name: "SecurityToken",
routeTemplate: "api/token");
Run Code Online (Sandbox Code Playgroud)
在所有其他请求中,OPTIONS和GET都会调用CORS策略提供程序,一切正常.我调试了thinktecture.identitymodel和相应的响应,返回正确的令牌.
/ token资源的GET方法不会调用CORS策略提供程序..但为什么呢?CorsMessageHandler已加载但从未被调用.如何判断请求是否会触发CORS/CorsMessageHandler?
诊断跟踪:
w3wp.exe Information: 0 : Request, Method=OPTIONS, Url=https://localhost/myapp/api/token, Message='https://localhost/myapp/api/token'
w3wp.exe Information: 0 : Message='CorsPolicyProvider selected: 'System.Web.Http.Cors.EnableCorsAttribute'', Operation=MyPolicyProviderFactory.GetCorsPolicyProvider
w3wp.exe Information: 0 : Message='CorsPolicy selected: 'AllowAnyHeader: True, AllowAnyMethod: True, AllowAnyOrigin: True, PreflightMaxAge: null, SupportsCredentials: True, Origins: {}, Methods: {}, Headers: {}, ExposedHeaders: {}'', Operation=EnableCorsAttribute.GetCorsPolicyAsync
w3wp.exe Information: 0 : Message='CorsResult returned: 'IsValid: True, AllowCredentials: True, PreflightMaxAge: null, AllowOrigin: https://localhost:4433, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Thinktecture.IdentityModel 中的ResourceAuthorize属性,但一切都停止了,因为没有 owin 上下文。
我有一个设置授权管理器的 owin 启动类
[assembly: OwinStartup(typeof(My.WebApi.Startup))]
namespace My.WebApi
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
AuthConfig.Configure(app);
}
}
}
public class AuthConfig
{
public static void Configure(IAppBuilder app)
{
app.UseResourceAuthorization(new ResourceAuthorizationMiddlewareOptions
{
Manager = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IResourceAuthorizationManager)) as IResourceAuthorizationManager
});
}
}
Run Code Online (Sandbox Code Playgroud)
我知道它被检测到并被调用。但是后来,当从 中点击以下代码时IdentityModel,我得到一个空指针异常:
public static Task<bool> CheckAccessAsync(this HttpRequestMessage request, IEnumerable<Claim> actions, IEnumerable<Claim> resources)
{
var authorizationContext = new ResourceAuthorizationContext(
request.GetOwinContext().Authentication.User ?? Principal.Anonymous,
actions,
resources);
return request.CheckAccessAsync(authorizationContext);
}
Run Code Online (Sandbox Code Playgroud)
我已经通过并看到它是由 GetOwinContext() …
我开始在我的项目中使用ThinkTecture.IdentityModel,我面临一个严重的问题.请帮我一下.
错误1"类型'System.IdentityModel.Tokens.SecurityToken'在未引用的程序集中定义.您必须添加对程序集'System.IdentityModel,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的引用
Thinktecture.IdentityServer是否支持加密它发出的JWT令牌,例如保护令牌不被用于回复攻击?
如果是,客户端如何解密加密令牌?
我曾尝试在IdentityServer General Configuration中启用"Require Token Encryption",但是在我尝试登录后,我在身份服务器网页上收到"No encryption key available"消息.
有问题还是我错过了必需的设置?
jwt thinktecture-ident-model thinktecture-ident-server openid-connect