首页
学习
活动
专区
圈层
工具
发布

开式SSO
EN

Stack Overflow用户
提问于 2022-01-23 08:07:57
回答 1查看 463关注 0票数 0

当用户从site https://www.siteA.com登录时,将记录身份验证cookie。

我想使用https://www.siteB.com从site User.Identity.Name读取这个身份验证cookie。

如何配置站点Program.cs(ASP.NET Core6.0)的站点https://www.siteA.com和站点https://www.siteB.com

代码语言:javascript
复制
      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();
EN

回答 1

Stack Overflow用户

发布于 2022-06-16 02:50:43

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

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

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

希望这能帮上忙

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70820227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档