IdentityServer4 ASP.NET Core Identity 不会重定向回客户端

我有带有 Asp.Net Core Identity 的基本 IdentityServer4。重定向到登录页面并登录后,IdentityServer 不会将我重定向回客户端。


身份服务器配置:


 new Client

            {

                ClientId = "mvc",

                ClientName = "MVC Client",

                AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,


                ClientSecrets =

                {

                    new Secret("secret".Sha256())

                },


                RedirectUris = { "http://localhost:50309/signin-oidc" },

                PostLogoutRedirectUris = { "http://localhost:50309/signout-callback-oidc" },


                AllowedScopes =

                {

                    IdentityServerConstants.StandardScopes.OpenId,

                    IdentityServerConstants.StandardScopes.Profile,

                    "api1"

                },

                AllowOfflineAccess = true

            }

IdentityServer 启动:


public void ConfigureServices(IServiceCollection services)

    {

        services.Configure<CookiePolicyOptions>(options =>

        {

            // This lambda determines whether user consent for non-essential cookies is needed for a given request.

            options.CheckConsentNeeded = context => true;

            options.MinimumSameSitePolicy = SameSiteMode.None;

        });


        services.AddDbContext<ApplicationDbContext>(options =>

            options.UseSqlServer(

                Configuration.GetConnectionString("DefaultConnection")));


        services.AddDefaultIdentity<IdentityUser>()

            .AddEntityFrameworkStores<ApplicationDbContext>()

            .AddDefaultTokenProviders()

            .AddDefaultUI();


        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);


        services.Configure<IISOptions>(iis =>

        {

            iis.AuthenticationDisplayName = "Windows";

            iis.AutomaticAuthentication = false;

        });


烙印99
浏览 306回答 3
3回答

慕容708150

从您的代码中,请将http更改为 https身份服务器仅适用于 https RedirectUris = { "&nbsp;http://localhost:50309/signin-oidc&nbsp;" },PostLogoutRedirectUris = { "&nbsp;http://localhost:50309/signout-callback-oidc&nbsp;" },并且在您的 MVC 客户端中,您也需要更改它。options.Authority = "&nbsp;http://localhost:5000&nbsp;";

素胚勾勒不出你

登录后我遇到了与重定向相同的问题。就我而言,我删除了 IdentityServer 项目的 launchsettings.json 中的 SSL 端点。IMO 在本地测试时不使用 SSL 应该没问题。不过,这就是导致我出现问题的原因。添加 SSL 端点解决了该问题。IE{&nbsp; "profiles": {&nbsp; &nbsp; "SelfHost": {&nbsp; &nbsp; &nbsp; "commandName": "Project",&nbsp; &nbsp; &nbsp; "launchBrowser": true,&nbsp; &nbsp; &nbsp; "environmentVariables": {&nbsp; &nbsp; &nbsp; &nbsp; "ASPNETCORE_ENVIRONMENT": "Development"&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; "applicationUrl": "https://localhost:5001"&nbsp; &nbsp; },&nbsp; &nbsp; "<YOUR-PROJECT-NAME>": {&nbsp; &nbsp; &nbsp; "commandName": "Project",&nbsp; &nbsp; &nbsp; "launchBrowser": true,&nbsp; &nbsp; &nbsp; "environmentVariables": {&nbsp; &nbsp; &nbsp; &nbsp; "ASPNETCORE_ENVIRONMENT": "Development"&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; "applicationUrl": "https://localhost:5001"&nbsp; &nbsp; }&nbsp; }}我还必须将课程中的 issuerUri 更新Startup为services.AddIdentityServer(options =>&nbsp;{&nbsp; &nbsp; options.IssuerUri = "https://localhost:5001"});我在文档中也找不到任何关于此的信息。我花了几个小时试图解决这个问题,发生这种情况时日志中没有错误,即使配置了详细日志记录,您也无法追踪导致它的原因。

陪伴而非守候

也许这是问题所在:https://github.com/aspnet/Announcements/issues/301您正在代码中设置 https 重定向,但未指定任何端口。尝试添加配置或删除app.UseHttpsRedirection();
打开App,查看更多内容
随时随地看视频慕课网APP