【问题标题】:Asp .Net Identity Server - Allow wildcard redirect URLs for VercelAsp .Net Identity Server - 允许 Vercel 的通配符重定向 URL
【发布时间】:2022-10-02 01:08:16
【问题描述】:

我正在使用带有 RestApi 的 Duende IdentityServer 作为后端,我正在使用 Vercel 测试前端,但由于不允许使用 vercel 的 redirectUrl,所以无法使用 vercel 登录 IdentityServer。

我确实在其他问题中看到了一些关于它的信息,但它是几年前的,并没有真正涵盖这个问题,我想知道是否有人设法在身份服务器中实现解决方案并可以共享信息和代码。

由于安全原因,我知道通配符重定向 URL 很糟糕,但这仅适用于开发环境,不会成为发布的一部分。

我刚开始接触 Asp .Net,任何帮助都将不胜感激!

    标签: asp.net .net next.js identityserver4 vercel


    【解决方案1】:

    一种选择是使用AddAppAuthRedirectUriValidator 扩展方法,该方法:

    添加符合“AppAuth”(本机应用程序的 OAuth 2.0)的重定向 URI 验证器(进行严格验证,但也允许 http://127.0.0.1 随机端口)。

    builder.Services.AddIdentityServer()
        .AddApiAuthorization<ApplicationUser, ApplicationDbContext>()
        .AddAppAuthRedirectUriValidator();
    

    如果这还不够,您可以使用 AddRedirectUriValidator 扩展方法注册自己的重定向 URI 验证器:

    builder.Services.AddIdentityServer()
        .AddApiAuthorization<ApplicationUser, ApplicationDbContext>()
        .AddRedirectUriValidator<MyRedirectUriValidator>();
    

    MyRedirectUriValidator.cs:

    // allows arbitrary redirect URIs - only for demo purposes. NEVER USE IN PRODUCTION
    public class MyRedirectUriValidator : IRedirectUriValidator
    {
        public Task<bool> IsPostLogoutRedirectUriValidAsync(string requestedUri, Duende.IdentityServer.Models.Client client)
        {
            return Task.FromResult(true);
        }
    
        public Task<bool> IsRedirectUriValidAsync(string requestedUri, Duende.IdentityServer.Models.Client client)
        {
            return Task.FromResult(true);
        }
    }
    

    Duende IdentityServer DI Extension Methods

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 2017-10-18
      • 2016-07-25
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 2011-08-25
      相关资源
      最近更新 更多