【发布时间】:2018-04-30 07:16:25
【问题描述】:
我正在查看下面的代码。 AddAuthentication 添加了带有“Cookies”的 defaultScheme。这是否意味着当前的mvc应用默认只接受Cookie认证而不接受Access Token。
services.AddOptions();
//services.Configure(Configuration);
services.AddDistributedMemoryCache(); // Adds a default in-memory implementation of IDistributedCache
services.AddSession();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
目前,我想通过我的移动应用程序访问一个页面,该应用程序使用从应用程序本身登录的访问令牌进行身份验证。 我想知道如何使用 AccessToken 而不是 Cookie 来请求我的 webview 中的网页。
我可以传入具有不同可接受方案的 Authorize 属性。我想知道这是设置它的方法。
[Authorize(AuthenticationSchemes =
JwtBearerDefaults.AuthenticationScheme)]
这仅适用于 Accesstoken,如果我需要两者我也添加 cookie
【问题讨论】:
-
您需要在身份验证方法中使用
AddJwtBearer(options => { ... });才能使用访问令牌。 -
这会影响所有可以使用访问令牌访问的页面吗?
标签: authentication asp.net-core access-token identityserver4