Identity Server 4 无限循环

2023-12-30

我正在开发一个 asp.net core 2.1 项目,其中安装了身份服务器 4,用户使用实体框架存储在 SQL 数据库中。 Web 项目有一个登录页面和登录成功后的仪表板。

请在 Startup.cs 中找到以下代码,

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        string connectionString = Configuration.GetConnectionString("DefaultConnection");
        var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

        services.AddMvc();

        services.AddDbContext<ApplicationDbContext>(builder =>
            builder.UseSqlServer(connectionString, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)));

        services.AddDbContext<SingleSignOn_dbContext>(builder =>
            builder.UseSqlServer(connectionString));

        services.AddIdentity<IdentityUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>();

        services.AddIdentityServer(options =>
        {
            options.UserInteraction.LoginUrl = "/Master/Login"; // Set the default login page for Identity server.
        }).AddOperationalStore(options =>
                options.ConfigureDbContext = builder =>
                   builder.UseSqlServer(connectionString, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)))

            .AddConfigurationStore(options =>
                options.ConfigureDbContext = builder =>
                    builder.UseSqlServer(connectionString, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)))
            .AddAspNetIdentity<IdentityUser>()
            .AddDeveloperSigningCredential();

        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.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Master/Error");
            app.UseHsts();
        }

        // Only need to run this once.
        InitializeDbTestData(app);

        app.UseIdentityServer();
        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseCookiePolicy();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Master}/{action=Login}/{id?}");
        });
    }

IDS 中的客户端详细信息如下:

 new Client {
                    ClientId = "SingleSignOnInternalClient",
                    ClientName = "Example Implicit Client Application",
                    AllowedGrantTypes = GrantTypes.Implicit,
                    AllowAccessTokensViaBrowser = true,
                    AllowedScopes = new List<string>
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        IdentityServerConstants.StandardScopes.Email,
                        "role",
                        "customAPI.write"
                    },
                    AllowedCorsOrigins = new List<string> {"192.168.6.112"},
                    RedirectUris = new List<string> {"https://localhost:44330/signin-oidc"},  // Configuration.GetSection("TestClient").GetSection("RedirectURL").Value
                    PostLogoutRedirectUris = new List<string> {"https://localhost:44330"},
                    RequireConsent = false,
                    AllowRememberConsent = false,
                    AccessTokenType = AccessTokenType.Jwt
                },

我使用 asp.net core 2.1 创建了一个客户端项目,并在联系页面(主控制器)中授权属性。 当我们点击联系页面时,当用户授权成功时,它会重定向到安装了身份服务器的另一个项目的登录页面。页面被重定向到无限循环。

客户端启动文件:

 public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {

        JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

        // Use cooking authentication for signing in users.
        services.AddAuthentication(options =>
        {
            options.DefaultScheme = "cookie";
            options.DefaultChallengeScheme = "oidc";
            options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;

        })
        .AddCookie("cookie")
        .AddOpenIdConnect("oidc", options =>
        {
            options.Authority = Configuration.GetValue<string>("Authority:EndPoint");    //services.Configure<"Authority">(Configuration.GetSection("EndPoint"));
            options.ClientId = "SingleSignOnInternalClient";
            options.SignInScheme = "cookie";
            options.SaveTokens = true;
            //options.GetClaimsFromUserInfoEndpoint = true;    
            options.RequireHttpsMetadata = false;
        });

        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => false;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection")));
        services.AddDefaultIdentity<IdentityUser>()
            .AddEntityFrameworkStores<ApplicationDbContext>();

        services.AddMvc(options =>
        {
            ///options.Filters.Add

        }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseCookiePolicy();

        app.UseAuthentication();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

客户端输出日志(无限重定向循环):

Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求启动 HTTP/1.1 POSThttp://localhost:44330/signin-oidc http://localhost:44330/signin-oidc应用程序/x-www-form-urlencoded 1473 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler:信息:AuthenticationScheme:cookie 已登录。 Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求在 5.4353ms 内完成 302 Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求启动 HTTP/1.1 GEThttp://localhost:44330/Home/联系方式 http://localhost:44330/Home/Contact
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:信息:与{action =“Contact”,controller =“Home”,page =“”,area =“”}匹配的路由。在控制器 IdentityTestClient.Controllers.HomeController (IdentityTestClient) 上执行带有签名 Microsoft.AspNetCore.Mvc.IActionResult Contact() 的控制器操作。 Microsoft.AspNetCore.Authorization.DefaultAuthorizationService:信息:授权失败。 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:信息:过滤器“Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter”处的请求授权失败。 Microsoft.AspNetCore.Mvc.ChallengeResult:信息:使用身份验证方案执行 ChallengeResult ()。 Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler:信息:AuthenticationScheme:oidc 受到质疑。 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:信息:在 8.3527 毫秒内执行操作 IdentityTestClient.Controllers.HomeController.Contact (IdentityTestClient) Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求在 17.5244ms 内完成 302

无限循环的 URL 如下,

这两个项目都配置了 SSL 以在本地运行 https。

我正在尝试实现单点登录解决方案,该解决方案在不同域中具有多个网站并使用身份服务器进行登录。 任何意见将不胜感激。


services.AddDefaultIdentity<IdentityUser>().AddEntityFrameworkStores<ApplicationDbContext>();

不需要客户端。 除了其他内容之外,只有您的 IdP 应该有权访问,它会重新配置您的身份验证方案参数。您可以随时将您的配置与最低工作一 https://github.com/IdentityServer/IdentityServer4/blob/master/samples/Quickstarts/3_ImplicitFlowAuthentication/src/MvcClient/Startup.cs来自官方存储库。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Identity Server 4 无限循环 的相关文章

  • 如何为 C 分配的 numpy 数组注册析构函数?

    我想在 C C 中为 numpy 数组分配数字 并将它们作为 numpy 数组传递给 python 我可以做的PyArray SimpleNewFromData http docs scipy org doc numpy reference
  • 如何将 #ifdef DEBUG 添加到 Xcode?

    我的项目中有一些代码永远不应该在发布版本中使用 但在测试时很有用 我想做这样的事情 ifdef DEBUG Run my debugging only code endif 在 Xcode 4 中哪里添加 DEBUG 设置 我尝试将其放入
  • 如何修复此错误“GDI+ 中发生一般错误”?

    从默认名称打开图像并以默认名称保存 覆盖它 我需要从 Image Default jpg 制作图形 将其放在 picturebox1 image 上并在 picurebox1 上绘制一些图形 它有效 这不是我的问题 但我无法保存 pictu
  • 单元测试一起运行时失败,单独运行时通过

    所以我的单元测试遇到了一些问题 我不能只是将它们复制并粘贴到这里 但我会尽力而为 问题似乎是 如果我一项一项地运行测试 一切都会按预期进行 但如果我告诉它一起运行测试 则 1 5 将通过 TestMethod public void Obj
  • 如何在 C# 中定义文本框数组?

    您好 当我在 Windows 申请表上创建文本框时 我无法将其命名为 box 0 box 1 等 我这样做的目的是因为我想循环使用它们 其实我发现TextBox array firstTextBox secondTextBox 也有效
  • 如何在 Linq 中获得左外连接?

    我的数据库中有两个表 如下所示 顾客 C ID city 1 Dhaka 2 New york 3 London 个人信息 P ID C ID Field value 1 1 First Name Nasir 2 1 Last Name U
  • 未经许可更改内存值

    我有一个二维数组 当我第一次打印数组的数据时 日期打印正确 但其他时候 array last i 的数据从 i 0 到 last 1 显然是一个逻辑错误 但我不明白原因 因为我复制并粘贴了 for 语句 那么 C 更改数据吗 I use g
  • C++:.bmp 到文件中的字节数组

    是的 我已经解决了与此相关的其他问题 但我发现它们没有太大帮助 他们提供了一些帮助 但我仍然有点困惑 所以这是我需要做的 我们有一个 132x65 的屏幕 我有一个 132x65 的 bmp 我想遍历 bmp 并将其分成小的 1x8 列以获
  • 如何编写一个同时需要请求和响应Dtos的ServiceStack插件

    我需要提供本地化数据服务 所有本地化的响应 Dto 都共享相同的属性 IE 我定义了一个接口 ILocalizedDto 来标记那些 Dto 在请求端 有一个ILocalizedRequest对于需要本地化的请求 Using IPlugin
  • HttpWebRequest 在第二次调用时超时

    为什么以下代码在第二次 及后续 运行时超时 代码挂在 using Stream objStream request GetResponse GetResponseStream 然后引发 WebException 表示请求已超时 我已经尝试过
  • 如何从main方法调用业务对象类?

    我已将代码分为业务对象 访问层 如下所示 void Main Business object public class ExpenseBO public void MakeExpense ExpensePayload payload var
  • .NET中的LinkedList是循环链表吗?

    我需要一个循环链表 所以我想知道是否LinkedList是循环链表吗 每当您想要移动列表中的 下一个 块时 以循环方式使用它的快速解决方案 current current Next current List First 电流在哪里Linke
  • 如何在按钮单击时模拟按键 - Unity

    我对 Unity 中的脚本编写非常陌生 我正在尝试创建一个按钮 一旦单击它就需要模拟按下 F 键 要拾取一个项目 这是我当前的代码 在编写此代码之前我浏览了所有统一论坛 但找不到任何有效的东西 Code using System Colle
  • 英特尔 Pin 与 C++14

    问题 我有一些关于在 C 14 或其他 C 版本中使用英特尔 Pin 的问题 使用较新版本从较旧的 C 编译代码很少会出现任何问题 但由于 Intel Pin 是操作指令级别的 如果我使用 C 11 或 C 14 编译它 是否会出现任何不良
  • Linq-to-entities,在一个查询中获取结果+行数

    我已经看到了有关此事的多个问题 但它们已经有 2 年 或更长 的历史了 所以我想知道这方面是否有任何变化 基本思想是填充网格视图并创建自定义分页 所以 我还需要结果和行数 在 SQL 中 这将类似于 SELECT COUNT id Id N
  • 将自定义 ValueProviderFactories 添加到 ASP.NET MVC3?

    我试图尝试将 Protobuf ValueProviderFactory 添加到 MVC3 以便我可以选择 MIME 类型并将原始数据反序列化为操作参数的对象 我还可以使用它来更改默认的 Json 序列化器 看着JsonValueProvi
  • 如何将 Roslyn 语义模型返回的类型符号名称与 Mono.Cecil 返回的类型符号名称相匹配?

    我有以下代码 var paramDeclType m semanticModel GetTypeInfo paramDecl Type Type Where paramDeclType ToString returns System Col
  • 使用 GhostScript.NET 打印 PDF DPI 打印问题

    我在用GhostScript NET http ghostscriptnet codeplex com打印 PDF 当我以 96DPI 打印时 PDF 打印效果很好 但有点模糊 如果我尝试以 600DPI 打印文档 打印的页面会被极大地放大
  • 检查Windows控制台中是否按下了键[重复]

    这个问题在这里已经有答案了 可能的重复 C 控制台键盘事件 https stackoverflow com questions 2067893 c console keyboard events 我希望 Windows 控制台程序在按下某个
  • 如何正确使用 std::condition_variable?

    我很困惑conditions variables以及如何 安全 使用它们 在我的应用程序中 我有一个创建 gui 线程的类 但是当 gui 是由 gui 线程构造时 主线程需要等待 情况与下面的函数相同 主线程创建互斥体 锁和conditi

随机推荐

  • xs:int 对于十进制值解组为 null

    我遇到了与基于 JAX WS 的 WebService 中的解组过程相关的问题 在 WSDL 文件中 有一个元素定义为
  • 将 JS 警报更改为 DOM 错误消息 div

    我需要将错误消息转换为定位的 div 最初隐藏 而不是标准的 js 警报 我意识到我需要将警报消息推送到 DOM 但我对 javascript 很陌生 任何帮助 将不胜感激 此外 我需要在没有确认的情况下执行此操作 因此错误消息会在字段焦点
  • 从 Spark 转换函数中动态读取 HDFS 文件

    如何在 Spark 函数中读取 HDFS 中的文件而不在函数中使用 SparkContext Example val filedata rdd rdd map x gt ReadFromHDFS x getFilePath 问题是如何实现
  • Python正则表达式解析特定标签后的组

    我有一个这样的文本列表 Something at the beginning References 1 Ryff C D 2014 Psychological Well Being Revisited Advances in the Sci
  • 如何定义取决于模板参数的字符类型的字符串文字?

    template
  • 如何按 dict 列过滤 pandas 数据框?

    给定一个数据帧 df serialnumber basicinfo 列 basicinfo 是一个字典 name xxx model xxx studyid xxx 有没有一种简单的方法可以通过字典键 模型 过滤此数据框 如果它是整数 我们
  • 正确实施乒乓球比赛

    我在一项作业中被要求实现正确调用 ping 和 pong 意思是在 ping 之前没有 pong 10 次的乒乓球游戏 意思是 控制台中的最终输出应该是 ping 1 pong 1 ping 2 pong 2 等 需求是用信号量 可重入锁和
  • 如何使用 selenium python 更改/删除样式属性?

    我想知道是否可以更改或删除 显示 无 在元素中使其在 python 中使用 selenium 可见
  • jquery的attr()是异步的吗?

    假设我有一个循环 它在每次迭代时都会附加一个带有 img 标签的 div 然后使用如下所示加载其 src 属性 img last attr src imageSource 如果我对几个不同的图像进行几次迭代 我是否会异步加载这些图像 如果没
  • Android 文本转语音男声

    我有一个工作文本到语音 但我想知道当应用程序调用它播放时 它会用男声代替女声吗 现在可以使用男声 女声并从应用程序 UI 动态更改 像这样定义 TTS 在构造函数中添加 google tts 引擎 tts new TextToSpeech
  • Android Canvas重做和撤消操作

    我正在做一个绘图项目 除了画布重做和撤消操作之外 我的代码运行良好 我的撤消操作从pathsArrayList 并保存到undonePathsArrayList 重做操作删除最后一个元素undonePaths并保存到paths 这是我的代码
  • 在 ntier 应用程序中传递数据

    如何将数据传递到 n 层应用程序中的层 我已经制定了 3 种不同的方法 A 通用 net 对象通用数据表 哈希表 通用数据集 字符串 整数等 然后使用数据集填充发送到 UI 层的业务对象 替代文本 http img11 imageshack
  • UIKeyboardWillShowNotification 不调用,仅 UIKeyboardWillHideNotification 在 iOS 9 中调用

    在 iOS 8 之前一切都运行良好 但是 当用户点击文本字段控件时 直接出现在 UIKeyboardWillHideNotification 通知中 登录控制台 找不到支持4型键盘iPhone PortraitTruffle NumberP
  • OpenGL ES 2.0 :glReadPixels() 带有 float 或 half_float 纹理

    我正在为 iPhone iOS 4 1 编写一个 OpenGL ES 2 0 应用程序 在着色器中完成的计算结束时 我需要将一些数据写回 CPU 据我所知 这可以通过 glReadPixels 来完成 为了保持精度 我想在着色器之间使用 h
  • 使用 python 和 twitterApi 将多个图像添加到推文中?

    您好 我一直在尝试使用 python 中的 twitterAPI 模块将四个图像添加到推文中 不幸的是 下面的代码仅渲染推文中数据中的其中一个图像 有人可以指出我在推文中附加四张图片的正确方向吗 我的代码如下 减去导入和密钥 api Twi
  • 求解积分极限

    我需要以数值方式找到积分的极限 并知道该积分的结果 我需要解决的是 正如你所看到的 这是不完整的 beta 函数 我知道a b and c 积分极限来自0 to x 我需要找到x The fzero函数可以求解各种非线性方程 首先 计算不完
  • pthread_create内存泄漏

    我使用C语言和Linux作为我的编程平台 在我的应用程序中 我调用 pthread create 然后我使用 ps 命令行工具检查应用程序的内存使用情况 它在 VSZ 列中添加了 4 但问题是当pthread create函数处理程序退出时
  • 从 UIImage 转换为 SwiftUI Image 会产生相同大小的空白图像

    我正在尝试转换UIImage https developer apple com documentation uikit uiimage到 SwiftUIImage https developer apple com documentati
  • Javascript 即时创建

    我有一个与此类似的链接 a href home category blog 1 Blog a 如您所见 该链接的 ID 为 博客 我想要做的是使用所单击的链接中的 ID 动态创建一个 div 因此如果单击 博客 则标记将为 div div
  • Identity Server 4 无限循环

    我正在开发一个 asp net core 2 1 项目 其中安装了身份服务器 4 用户使用实体框架存储在 SQL 数据库中 Web 项目有一个登录页面和登录成功后的仪表板 请在 Startup cs 中找到以下代码 public class