signin-oidc redirect uri in authorization code flow

Viewed 714

I am trying to understand the Authorization code flow in Identity Server. I am able to run hte sample application, but just trying to understand the signin-oidc redirect URL.

Identity Server runs in port 5000 and client app runs in port 5006

Here is snippet from client project. Added Authentication and Authorization middleware in configure method.

Scenario 1

 services.AddAuthentication(opts => 
        {
            opts.DefaultScheme = "Cookies";
            opts.DefaultChallengeScheme = "oidc";
        })
        .AddCookie("Cookies")
        .AddOpenIdConnect("oidc", opts => 
        {
            opts.Authority = "https://localhost:5000";
            opts.RequireHttpsMetadata = true;
            opts.ClientId = "AuthCode_Flow_Client";
            opts.ClientSecret = "secret";
            opts.SaveTokens = true;
            opts.ResponseType = "code";
            opts.Scope.Add("ValuesAPI_ReadOnly");   
        });

In my identity Server, I have the client settings as below.

 new Client()
             {
                 ClientId = "AuthCode_Flow_Client",
                 ClientName = "AuthCode Client Application",
                 AllowedGrantTypes = { GrantType.AuthorizationCode },
                   ClientSecrets = { new Secret("secret".Sha256()) },
                   RedirectUris = { "https://localhost:5006/signin-oidc" },
                   AllowedScopes  = {
                                        IdentityServerConstants.StandardScopes.OpenId,
                                        IdentityServerConstants.StandardScopes.Profile,
                                        "ValuesAPI_ReadOnly" 
                                    }
             },

This works fine for me. once I login successfully, I get redirected to https://localhost:5006/signin-oidc. From here a back channel req is made to connect/token endpoint with the received code and the access token is received. Good.

Scenario 2

Now I just change the redirect URL in my client settings as below.

new Client()
             {
                 ClientId = "AuthCode_Flow_Client",
                 ClientName = "AuthCode Client Application",
                 AllowedGrantTypes = { GrantType.AuthorizationCode },
                   ClientSecrets = { new Secret("secret".Sha256()) },
                   RedirectUris = { "https://localhost:5006/invalidpath" },
                   AllowedScopes  = {
                                        IdentityServerConstants.StandardScopes.OpenId,
                                        IdentityServerConstants.StandardScopes.Profile,
                                        "ValuesAPI_ReadOnly" 
                                    }
             },

I have given invalid url in redriecturi's. now on running I get an exception, that invlid redirect_uri.. fine.. so I came to conclusion that openIdConnect middleware is handling the signin-oidc route and requesting for token in back channel.

Scenario 3

I make changes in both client app as well as identity server.

services.AddAuthentication(opts => 
        {
            opts.DefaultScheme = "Cookies";
            opts.DefaultChallengeScheme = "oidc";
        })
        .AddCookie("Cookies")
        .AddOpenIdConnect("oidc", opts => 
        {
            opts.Authority = "https://localhost:5000";
            opts.RequireHttpsMetadata = true;
            opts.ClientId = "AuthCode_Flow_Client";
            opts.CallbackPath = "/invalidpath";
            opts.ClientSecret = "secret";
            opts.SaveTokens = true;
            opts.ResponseType = "code";   
            opts.Scope.Add("ValuesAPI_ReadOnly");
        });

In my identity Server, I have the client settings as below.

 new Client()
             {
                 ClientId = "AuthCode_Flow_Client",
                 ClientName = "AuthCode Client Application",
                 AllowedGrantTypes = { GrantType.AuthorizationCode },
                   ClientSecrets = { new Secret("secret".Sha256()) },
                   RedirectUris = { "https://localhost:5006/invalidpath" },
                   AllowedScopes  = {
                                        IdentityServerConstants.StandardScopes.OpenId,
                                        IdentityServerConstants.StandardScopes.Profile,
                                        "ValuesAPI_ReadOnly" 
                                    }
             },

This works fro me.. The redierct URL is invalid. The callback path that I mentioed in my client app is also invalid. how is hte back channel request is being made with ClientId, clientSecret and code.

Could anyone explain how this back channel is being made.

1 Answers

In my opinion #identity4 logs will help you, please check them in details.

Related