I am using Microsoft.Owin in my MVC web project to call IdentityServer4.
My Startup file is;
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = Settings.SignInAsAuthenticationType // "Cookies";
});
app.UseOpenIdConnectAuthentication(openIdConnectOptions: new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "oidc",
Authority = Settings.AuthorityUrl, //ID Server, "https://localhost:44314/"; https://localhost:44307/
ClientId = Settings.ClientId, // "SIR"
Scope = Settings.Scope, // "openid profile";
ResponseType = Settings.ResponseType, // "id_token code";
SignInAsAuthenticationType = Settings.SignInAsAuthenticationType,
//--------------------------------------// "Cookies";
RedirectUri = Settings.RedirectUri, // URL of website, http://localhost:53200/signin-oidc;
RequireHttpsMetadata = Settings.RequireHttpsMetadata,
//--------------------------------------// true
ClientSecret = "secret"
});
app.Use(async (ctx, next) =>
{
var message = ctx.Authentication.User.Identity.IsAuthenticated
? $"User: {ctx.Authentication.User.Identity.Name}"
: "User Not Authenticated";
await next();
});
}
}
My in memory client in IdentityServer4 is;
public static IEnumerable<Client> Clients()
{
return new[]
{
new Client
{
ClientId = "SIR",
ClientName = "SIR",
AllowedGrantTypes = GrantTypes.Hybrid,
AllowedScopes = new[]
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile
},
RedirectUris = {
"https://localhost:44314",
"http://localhost:53200/signin-oidc"
},
ClientSecrets = { new Secret("secret".Sha256())}
}
};
}
The NullReferenceException in the AddQueryString method is caused by the url field being null. I do not know why this field is null.
IdentityServer4.Endpoints.AuthorizeEndpoint:Information: ValidatedAuthorizeRequest { "ClientId": "SIR", "ClientName": "SIR", "RedirectUri": "http://localhost:53200/signin-oidc", "AllowedRedirectUris": [ "https://localhost:44314", "http://localhost:53200/signin-oidc" ], "SubjectId": "anonymous", "ResponseType": "code id_token", "ResponseMode": "form_post", "GrantType": "hybrid", "RequestedScopes": "openid profile", "State": "OpenIdConnect.AuthenticationProperties=WBfqf-a6W0K-0x6giakJP1GCkjUyG0wzOgAr9AuitPNyUb6wsIlzJN-Yvv-ARRdTd5huJIIl3N0mpI95EbLzGKIVmAhXr4JiIWKo2dOCTFI7PH218T9V1vVkKP3kFmQgtRRYRagG9YEA2PvyMtxzQXMf4v3pPequ8Am7H_8TIfgMqspxAnTsXQ4K-cD_TBTVFc45AiDiylpWup1_Ovrpqu700JCGimHZJRuXP25MHMs", "Nonce": "636809130138863279.M2IyNTYyZTgtZTk0Ni00OWU5LWI4MmMtNGU2MWY4M2FkMzQzNzExYjRjYjYtOWY4MC00NjQwLWEyZGYtYzgzYjljZTY4ZDFj", "Raw": { "client_id": "SIR", "redirect_uri": "http://localhost:53200/signin-oidc", "response_mode": "form_post", "response_type": "id_token code", "scope": "openid profile", "state": "OpenIdConnect.AuthenticationProperties=WBfqf-a6W0K-0x6giakJP1GCkjUyG0wzOgAr9AuitPNyUb6wsIlzJN-Yvv-ARRdTd5huJIIl3N0mpI95EbLzGKIVmAhXr4JiIWKo2dOCTFI7PH218T9V1vVkKP3kFmQgtRRYRagG9YEA2PvyMtxzQXMf4v3pPequ8Am7H_8TIfgMqspxAnTsXQ4K-cD_TBTVFc45AiDiylpWup1_Ovrpqu700JCGimHZJRuXP25MHMs", "nonce": "636809130138863279.M2IyNTYyZTgtZTk0Ni00OWU5LWI4MmMtNGU2MWY4M2FkMzQzNzExYjRjYjYtOWY4MC00NjQwLWEyZGYtYzgzYjljZTY4ZDFj", "x-client-SKU": "ID_NET461", "x-client-ver": "5.3.0.0" } }
IdentityServer4.ResponseHandling.AuthorizeInteractionResponseGenerator:Information: Showing login: User is not authenticated
IdentityServer4.ResponseHandling.AuthorizeInteractionResponseGenerator:Information: Showing login: User is not authenticated
IdentityServer4.ResponseHandling.AuthorizeInteractionResponseGenerator:Information: Showing login: User is not authenticated
IdentityServer4.ResponseHandling.AuthorizeInteractionResponseGenerator:Information: Showing login: User is not authenticated Exception thrown: 'System.NullReferenceException' in IdentityServer4.dll
Exception thrown: 'System.NullReferenceException' in IdentityServer4.dll 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.6\System.Diagnostics.StackTrace.dll'. Symbols loaded. 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.6\System.Reflection.Metadata.dll'. Symbols loaded. 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.6\System.IO.MemoryMappedFiles.dll'. Symbols loaded.
IdentityServer4.Hosting.IdentityServerMiddleware:Critical: Unhandled exception: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object. at IdentityServer4.Extensions.StringExtensions.AddQueryString(String url, String query) in C:\local\identity\server4\IdentityServer4\src\Extensions\StringsExtensions.cs:line 197 at IdentityServer4.Endpoints.Results.LoginPageResult.ExecuteAsync(HttpContext context) in C:\local\identity\server4\IdentityServer4\src\Endpoints\Results\LoginPageResult.cs:line 61 at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) in C:\local\identity\server4\IdentityServer4\src\Hosting\IdentityServerMiddleware.cs:line 59 IdentityServer4.Hosting.IdentityServerMiddleware:Critical: Unhandled exception: Object reference not set to an instance of an object.
It looks like due to the commit 4dea55de86cafd57024a8e299693fc939169375b
Properties of the class UserInteractionOptions are no longer being set by default.
In order to fix that you must provide those options in configuration.
Ex.
services.AddIdentityServer(options =>
{
options.UserInteraction = new UserInteractionOptions()
{
LogoutUrl = "/account/logout",
LoginUrl = "/account/login",
LoginReturnUrlParameter = "returnUrl"
};
})
It looks like due to the commit 4dea55d
Properties of the class UserInteractionOptions are no longer being set by default.
Yes, given how ASP.NET Identity changed, we had to rework this to accommodate it. In short, the settings on the cookie options really are what should control those URLs. If you set them on IdentityServer, then we honor them, but they may not be in sync with the paths on the cookie options (mainly due to ASP.NET Identity using different values).
So at this point -- do you still have an issue, or do you have your workaround?
So at this point -- do you still have an issue, or do you have your workaround?
I'll close since I didn't get a reply. If you have more info or further issues, please let us know.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
It looks like due to the commit 4dea55de86cafd57024a8e299693fc939169375b
Properties of the class
UserInteractionOptionsare no longer being set by default.In order to fix that you must provide those options in configuration.
Ex.