ASP.NET Core-2.0 - ArgumentException: Optionen.ClientId müssen zur Verfügung gestellt werden
Habe ich eine .NET-Core-1.1-Anwendung ist, dass ich wünschte, ein upgrade auf .NET Core 2.0. Beim aktualisieren der Ziel-framework und alle Abhängigkeiten, fand ich, dass meine Authentifizierung setup würde nicht kompilieren. Ich habe aktualisiert, um Konto für entfernte Eigenschaften und veraltet/verschobene Methode aufruft. Ellipsen repräsentieren, der code aus Platzgründen weggelassen.
Ich nun die folgende Fehlermeldung wenn ich meine Anwendung
1.1 Code - Inside public void Configure()
Methode von Startup.cs
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies",
ExpireTimeSpan = TimeSpan.FromHours(12),
SlidingExpiration = false,
CookiePath = CookiePath,
CookieName = "MyCookie"
});
var openIdConnectionOptions = new OpenIdConnectOptions
{
ClientId = Configuration["OpenIdSettings:ClientId"],
ClientSecret = Configuration["OpenIdSettings:ClientSecret"],
Authority = Configuration["OpenIdSettings:Authority"],
MetadataAddress = $"{Configuration["OpenIdSettings:Authority"]}/.well-known/openid-configuration",
GetClaimsFromUserInfoEndpoint = true,
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
ResponseType = OpenIdConnectResponseType.IdToken,
TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
//This sets the value of User.Identity.Name to users AD username
NameClaimType = IdentityClaimTypes.WindowsAccountName,
RoleClaimType = IdentityClaimTypes.Role,
AuthenticationType = "Cookies",
ValidateIssuer = false
}
};
//Scopes needed by application
openIdConnectionOptions.Scope.Add("openid");
openIdConnectionOptions.Scope.Add("profile");
openIdConnectionOptions.Scope.Add("roles");
app.UseOpenIdConnectAuthentication(openIdConnectionOptions);
Alles, was ich lese zeigt dieser Prozess wurde verschoben, um die ConfigureServices
Methode. Hier ist mein neuer code für Core 2.0
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
}).AddCookie(options => new CookieAuthenticationOptions
{
//AuthenticationScheme = "Cookies", //Removed in 2.0
ExpireTimeSpan = TimeSpan.FromHours(12),
SlidingExpiration = false,
Cookie = new CookieBuilder
{
Path = CookiePath,
Name = "MyCookie"
}
}).AddOpenIdConnect(options => GetOpenIdConnectOptions());
...
}
public void Configure(IApplicationBuilder app)
{
...
app.UseAuthentication();
...
}
private OpenIdConnectOptions GetOpenIdConnectOptions()
{
var openIdConnectionOptions = new OpenIdConnectOptions
{
ClientId = Configuration["OpenIdSettings:ClientId"],
ClientSecret = Configuration["OpenIdSettings:ClientSecret"],
Authority = Configuration["OpenIdSettings:Authority"],
MetadataAddress = $"{Configuration["OpenIdSettings:Authority"]}/.well-known/openid-configuration",
GetClaimsFromUserInfoEndpoint = true,
SignInScheme = "Cookies",
ResponseType = OpenIdConnectResponseType.IdToken,
TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
//This sets the value of User.Identity.Name to users AD username
NameClaimType = IdentityClaimTypes.WindowsAccountName,
RoleClaimType = IdentityClaimTypes.Role,
AuthenticationType = "Cookies",
ValidateIssuer = false
}
};
//Scopes needed by application
openIdConnectionOptions.Scope.Add("openid");
openIdConnectionOptions.Scope.Add("profile");
openIdConnectionOptions.Scope.Add("roles");
return openIdConnectionOptions;
}
Ich bin Einstellung der ClientId (oder so dachte ich) in meiner GetOpenIdConnectOptions
also ich bin unklar, auf welche ClientId der Fehler bezieht.enter code here
Bearbeiten:
appsettings.json
"OpenIdSettings": {
"Authority": "https://myopenidauthenticationendpointurl",
"ClientId": "myappname",
"CookiePath": "mypath"
}
- Tut
Configuration["OpenIdSettings:ClientId"]
einen Wert? - Hinzugefügt edit original-Beitrag mit
OpenIdSettings
im Abschnitt " appsetting.json
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ihre
GetOpenIdConnectOptions()
Helfer gibt ein neuesOpenIdConnectOptions
- Instanz anstelle der Aktualisierung deroptions
Objekt für Sie vorbereitet von deroptions => ...
delegieren.Fixieren Sie Ihre Methode, um eine bestehende
OpenIdConnectOptions
Wert und es sollte funktionieren: