【发布时间】:2018-02-15 13:49:14
【问题描述】:
在我的 .net core 1.1 代码中,我按如下方式进行身份验证(将不记名令牌发送到外部 URL 并在返回令牌中查找声明)。此代码在Configure 方法中
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
Authority = signinAuthority,
RequireHttpsMetadata = signinHTTPS,
ClientId = "skybus",
ClientSecret = "secret",
ResponseType = "code id_token",
Scope = { "api1", "offline_access" },
GetClaimsFromUserInfoEndpoint = true,
SaveTokens = true
});
现在我将代码升级到 .net Core 2.0,UseCookieAuthentication 和 UseOpenIdConnectAuthentication 都已更改。我发现在这种情况下很难找到需要做的事情
我在ConfigureServices方法中改成如下
services.AddAuthentication(options => {
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(o =>
{
o.Authority = signinAuthority;
o.SignInScheme = "Cookies";
o.RequireHttpsMetadata = signinHTTPS;
o.ClientId = "skybus";
o.ClientSecret = "secret";
o.ResponseType = "code id_token";
o.GetClaimsFromUserInfoEndpoint = true;
o.SaveTokens = true;
o.Scope.Add("api1");
o.Scope.Add("offline_access");
});
在浏览器中,我在上述更改后看到了这个 URL。如果用户未登录,它应该向我显示外部登录页面或返回我网站的主页
【问题讨论】:
标签: c# .net authentication asp.net-core-1.1 .net-core-2.0