I have a .NET Core 1.1 application that I want to upgrade to .NET Core 2.0. After updating the target structure and all the dependencies, I found that my authentication setting would not compile. I updated to account for remote properties and obsolete / moved method calls. The ellipses used to represent the code are omitted for brevity.
Now I get the following error when starting the application 
1.1 Code - Inside public void Configure()the Startup.cs Method
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
{
NameClaimType = IdentityClaimTypes.WindowsAccountName,
RoleClaimType = IdentityClaimTypes.Role,
AuthenticationType = "Cookies",
ValidateIssuer = false
}
};
openIdConnectionOptions.Scope.Add("openid");
openIdConnectionOptions.Scope.Add("profile");
openIdConnectionOptions.Scope.Add("roles");
app.UseOpenIdConnectAuthentication(openIdConnectionOptions);
Everything I read shows that this process has moved on to the method ConfigureServices. Here is my new code for Core 2.0
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
}).AddCookie(options => new CookieAuthenticationOptions
{
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
{
NameClaimType = IdentityClaimTypes.WindowsAccountName,
RoleClaimType = IdentityClaimTypes.Role,
AuthenticationType = "Cookies",
ValidateIssuer = false
}
};
openIdConnectionOptions.Scope.Add("openid");
openIdConnectionOptions.Scope.Add("profile");
openIdConnectionOptions.Scope.Add("roles");
return openIdConnectionOptions;
}
I set ClientId (or so I thought) in mine GetOpenIdConnectOptions, so it is not clear what ClientId refers to.enter code here
:
appsettings.json
"OpenIdSettings": {
"Authority": "https://myopenidauthenticationendpointurl",
"ClientId": "myappname",
"CookiePath": "mypath"
}