Sorry, there was an error : invalid_request Missing openid scope IdentityServer4

Sorry, there was an error : invalid_request Missing openid scope IdentityServer4

我正在尝试通过 IdentityServe 授权 React 项目。

Sorry, there was an error : invalid_request
Missing openid scope
Request Id: 0HM6DDV35HLDE:00000001

告诉我可能是什么原因?看来网址是正确的。最有可能的原因是在配置参数中。

配置:

public static IEnumerable<Client> Clients =>new List<Client>
    {
       new Client
         {
            ClientId = "js_oidc",
            ClientName = "Javascript Client",
            AllowedGrantTypes = GrantTypes.Implicit,
            AllowAccessTokensViaBrowser = true,
        
            AbsoluteRefreshTokenLifetime = 200,
            IdentityTokenLifetime = 15,
            AccessTokenLifetime = 100,
            AuthorizationCodeLifetime = 15,
            SlidingRefreshTokenLifetime = 120,
        
            RedirectUris =
            {
                "http://localhost:3000/callback.html",
                "http://localhost:3000/silent.html"
            },
            PostLogoutRedirectUris = { "http://localhost:3000/index.html" },
            AllowedCorsOrigins = { "http://localhost:3000" },
        
            AllowedScopes =
            {
                IdentityServerConstants.StandardScopes.OpenId,
                IdentityServerConstants.StandardScopes.Profile,
                IdentityServerConstants.StandardScopes.Email,
                "api1"
            }
            }
        };

授权服务:

    constructor() {
    const settings = {
        authority: "http://localhost:5001/",
        client_id: "js_oidc",
        redirect_uri: "http://localhost:3000/callback.html",
        silent_redirect_uri: "http://localhost:3000/silent.html",
        post_logout_redirect_uri: "http://localhost:3000/index.html",
        scope: "api1"
    };
    this.userManager = new UserManager(settings);
  }
 

你必须要求

范围:“openid api1”

在您的客户端中,因为在使用 openid connect 时 openid 是必需的范围。

 <script src="oidc-client.min.js"></script>
    <script>
        new Oidc.UserManager({ response_mode: "query" }).signinRedirectCallback().then(function () {
            window.location = "index.html";
        }).catch(function (e) {
            console.error(e);
        });
    </script>
callback.html:21 Error: No state in response
    at e.t [as readSigninResponseState] (oidc-client.min.js:1)
    at e.t [as processSigninResponse] (oidc-client.min.js:1)
    at e.t [as _signinEnd] (oidc-client.min.js:47)
    at e.t [as signinRedirectCallback] (oidc-client.min.js:47)
    at callback.html:18