I'm not getting a scope checkbox when the Authorize tag doesn't contain roles, Ajax authorization request not sending scope either

后端 未结 2 1757
执笔经年
执笔经年 2021-01-22 19:21

UPDATE 2: If I change my controller Authorize tag from this

[Authorize]

to this

[Authorize(Roles = \"Read\")]
         


        
2条回答
  •  难免孤独
    2021-01-22 20:03

    Solution!! The last part was the hardest to figure out, which I finally did with the help of the Chrome Developer tools that showed a little red X on the network tag showing the following error message:

    XMLHttpRequest cannot load http://security.RogueOne.com/core/connect/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:62561' is therefore not allowed access.
    

    The error message finally connected the dots below, until then the on OAuthComplete complete JavaScript function would be called, but with no token. The network tab show "This request has no response data available", but I'd see a Content-Length in the Response headers with a content-type of Json. Fiddler also showed the response which looked like (and was) well formed JSON.

    I described this error here Swagger UI not parsing reponse which was due to IdentityServer3 correctly not adding a response header of "Access-Control-Allow-Origin:http://localhost:62561" You can force IdentityServer3 to send that header by updating you client creation to be the following:

    new Client
    {
        ClientName = "SwaggerUI",
        Enabled = true,
        ClientId = "swaggerUI",
        ClientSecrets = new List
        {
            new Secret("PasswordGoesHere".Sha256())
        },
        Flow = Flows.ClientCredentials,
        AllowClientCredentialsOnly = true,
        AllowedScopes = new List
        {
            "Read"
        },
    
        Claims = new List
        {
            new Claim("client_type", "headless"),
            new Claim("client_owner", "Portal"),
            new Claim("app_detail", "allow")
        },
        PrefixClientClaims = false
        // Add the AllowedCorOrigins to get the Access-Control-Allow-Origin header to be inserted for the following domains
        ,AllowedCorsOrigins = new List
        {
            "http://localhost:62561/"
            ,"http://portaldev.RogueOne.com"
            ,"https://portaldev.RogueOne.com"
        }
    }    
    

    The AllowedCorsOrigins was the last piece of my puzzle. Hopefully this helps someone else who is facing the same issue

提交回复
热议问题