【问题标题】:SSO with openiddictSSO 与 openiddict
【发布时间】:2022-06-16 10:50:43
【问题描述】:

当用户从站点https://www.siteA.com 登录时, 记录一个身份验证 cookie。

我想使用 User.Identity.Name 从站点 https://www.siteB.com 读取此身份验证 cookie。

我应该如何配置站点https://www.siteA.com和站点https://www.siteB.com的Program.cs(ASP.NET CORE 6.0)?

      using AuthorizationServer.Models;
      using Microsoft.AspNetCore.Authentication.Cookies;
      using Microsoft.EntityFrameworkCore;

      var builder = WebApplication.CreateBuilder(args);

      builder.Services.AddDbContext<DbContext>(options =>
        {
          options.UseInMemoryDatabase(nameof(DbContext));
          options.UseOpenIddict();
        });

       builder.Services.AddOpenIddict()

           .AddCore(options =>
             {
               options.UseEntityFrameworkCore()
              .UseDbContext<DbContext>();
             })

           .AddServer(options =>
             {
              options
                 .AllowClientCredentialsFlow();

              options
                .SetTokenEndpointUris("/connect/token");

              options
               .AddEphemeralEncryptionKey()
               .AddEphemeralSigningKey();

              options.RegisterScopes("api");

              options
               .UseAspNetCore()
               .EnableTokenEndpointPassthrough();
         });

        builder.Services.AddHostedService<TestData>();
        builder.Services.AddControllersWithViews();

       builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
          .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
                 {
                  options.LoginPath = "/account/login";
                 });

        var app = builder.Build();

        if (app.Environment.IsDevelopment())
        {
          app.UseDeveloperExceptionPage();
        }

        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthentication();

        app.UseEndpoints(endpoints =>
           {
             endpoints.MapDefaultControllerRoute();
           });


        app.Run();



【问题讨论】:

    标签: single-sign-on openiddict


    【解决方案1】:

    您可以在客户端应用程序(即 SiteA 和 SiteB)中使用 ASP.Net Core 数据保护密钥配置。

    看看这个。 https://github.com/openiddict/openiddict-core/issues/1109

    还有这个 https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-3.1

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2017-06-15
      • 2021-06-03
      • 2017-10-23
      • 2021-08-28
      • 2015-09-24
      • 2021-10-23
      • 2022-12-20
      • 2021-07-25
      • 2019-01-05
      相关资源
      最近更新 更多