首页 > 解决方案 > IdentityServer3 为授权端点返回 invalid_scope

问题描述

我在我的 ASP.NET MVC 网站上安装了 IdentityServer3 和一个定义如下的客户端(一个 NopCommerce 插件)(网址仅用于测试):

new Client
                   {
                       ClientName    = "Deep Stores",
                       ClientId      = "deepstores",
                       ClientSecrets = new List<Secret>
                                       {
                                           new Secret("0B0A3FD3-F30C-428C-B1A3-6E570103614D".Sha256())
                                       },
                       AccessTokenType = AccessTokenType.Reference,
                       RedirectUris    = new List<string>
                                         {
                                             "http://localhost:2030/plugins/ExternalAuthDeepStudies/logincallback"
                                         },
                       Flow                   = Flows.AuthorizationCode,
                       AllowAccessToAllScopes = true,
                       AllowedScopes          = StandardScopes.All.Select(x => x.Name).ToList()
                   }

当尝试使用如下所示的 url 获取授权令牌时,它第一次工作(出现登录并授予页面等等),但对于其余请求,它返回error=invalid_scope给我的回调!

请求授权端点:

https://127.0.0.1/core/connect/authorize?client_id=deepstores&redirect_uri=http%3A%2F%2Flocalhost%3A2030%2Fplugins%2FExternalAuthDeepStudies%2Flogincallback&scope=profile&response_type=code

怎么了?为什么我会收到这个错误?

范围定义为:

public static IEnumerable<Scope> Get()
    {
        return new[]
               {
                   StandardScopes.OpenId,
                   StandardScopes.Profile,
                   StandardScopes.Email,
                   StandardScopes.Address,
                   StandardScopes.Phone,
                   StandardScopes.OfflineAccess,
                   StandardScopes.RolesAlwaysInclude,
                   StandardScopes.AllClaims,

               };
    }

请注意,我使用 EntityFramework 并且我所有的员工都存储在数据库中。另外,我使用 ASP.NET Identity 来管理用户和角色。

标签: asp.net-mvcoauth-2.0openid-connectidentityserver3nopcommerce

解决方案


推荐阅读