Search code examples
azureasp.net-coreasp.net-identityazure-active-directoryidentityserver4

How to work with Azure AD external login with ASP.NET Idenity in Identity Server4


I follow below article to get work with asp.net identity in IdenityServer4: http://docs.identityserver.io/en/release/quickstarts/6_aspnet_identity.html

Now i want to add Azure AD as external Idp :

 services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryPersistedGrants()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddAspNetIdentity<ApplicationUser>();


        services.AddAuthentication()
           .AddOpenIdConnect("AAD", "Azure Active Directory", options =>
           {
               options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
               options.SignOutScheme = IdentityServerConstants.SignoutScheme;
               options.Authority = "https://login.microsoftonline.com/xxxxxx.onmicrosoft.com";
               options.ClientId = "xxxxxxx";
               options.Scope.Add("openid");
               options.Scope.Add("profile");
               options.TokenValidationParameters = new TokenValidationParameters
               {
                   ValidateIssuer = false
               };
               options.GetClaimsFromUserInfoEndpoint = true;
           });

But when i debug my application ==> redirect to identity server==>click AAD login . I notice when i reach the Azure AD username/password page ,my client app stops , so after enter the credentials and consent , i will stay on the identity server page . Can anyone provides some suggestions ?


Solution

  • The interesting part is when i turn to use chrome to start my client app in visual studio , the client app is not stopped anymore . Quite strange and not to find a explanation .