max*_*pan 3 asp.net-core identityserver4 asp.net-core-mvc-2.0
我已将我的项目升级到 asp.net 核心。但是现在我的 CookieAuthnetication 和 OpenIdConnectionAuthentication 方法不起作用。它们已经过时了。
Startup.cs 配置方法
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
Authority = "http://localhost:5000",
RequireHttpsMetadata = false,
ClientId = "integapay.client",
ClientSecret = "mySecret",
ResponseType = "code id_token",
Scope = { "openid", "profile", "api.public", "offline_access" },
GetClaimsFromUserInfoEndpoint = true,
SaveTokens = true
});
Run Code Online (Sandbox Code Playgroud)
他们将其移至配置服务部分
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthentication(options => {
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options => SetOpenIdConnectOptions(options));
}
private void SetOpenIdConnectOptions(OpenIdConnectOptions options)
{
options.Authority = Configuration["auth:oidc:authority"];
options.ClientId = Configuration["auth:oidc:clientid"];
options.RequireHttpsMetadata = false;
options.ClientSecret = Configuration["auth:oidc:clientSecret"];
options.SignInScheme = "Cookies";
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.ResponseType = "code id_token";
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("api_back");
options.Scope.Add("offline_access");
}
Run Code Online (Sandbox Code Playgroud)
在配置调用中,您只需调用
app.UseAuthentication();
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。:)
| 归档时间: |
|
| 查看次数: |
1043 次 |
| 最近记录: |