GetAuthorizationContextAsync(returnUrl) of IIdentityServerInteractionService return null during login

Viewed 4098

I created an Identity 4 app server using a template from the documentation. I defined that the database would be initially populated with 2 standard users. However, when I try to login using any of the previously created users, the page is refreshed and nothing happens. So I debugged it and it seems like this section returns null, when it should return the user data.

The code: var context = await _interaction.GetAuthorizationContextAsync(returnUrl);.

beingin

_interaction dependency injection of IIdentityServerInteractionService returnUrl = "/grants";

Versions

2 Answers

AuthorizationContext is a set of rules that defines login flow. returnUrl is not just an URL for redirect after login but also a signature (think as a client's login) that is used by IdentityServer to recognize a client (i.e. a piece of software which uses IdentityServer, don't mix up with users). returnUrl must be explicitly set in IdentityServer client's records - either in SQL tables or in Quickstart's config.cs where in-memory clients are populated.

returnUrl is captured as a parameter of the login URL: https://myidentityserver.com/Account/Login?ReturnUrl=/myreturnurl. If there is no matched client in the IdentityServer records, GetAuthorizationContextAsyncwill return null, this is expected and normal. However, it should not prevent user authorization if there is no client, i.e. a login occurs within IdentityServer itself, using its own UI.

This is in addition to Niksr's answer, which I found very helpful. Here is a return url for our Identity Server 4, running in local dev, URL decoded and line breaks for readability. In this environment we have a standalone identityserver4 webapp servicing multiple separate web apps. Each is a different client. As Niksr says, the ClientId distinguishes these.

?ReturnUrl=/connect/authorize/callback?client_id=ccccc
&redirect_uri=https%3A%2F%2Flocalhost%2Fsignin-oidc
&response_type=code%20id_token
&scope=openid%20profile
&state=OpenIdConnect.AuthenticationProperties%3D(~214 chars)
&response_mode=form_post
&nonce=(116 chars)
&code_challenge=(44 chars)
&code_challenge_method=S256
&x-client-SKU=ID_NET461
&x-client-ver=6.8.0.0

ccccc matches a value in [identityserver].[Clients].[ClientId]

Related