IdentityServer身份验证端点 - > error = invalid_request failureReason =“STATUS_CODE”

时间:2016-11-10 11:21:17

标签: .net oauth identityserver3 openid-connect

我目前正在为一项第三方服务实施SSO。该服务不支持OIDC或OAuth,因此我需要将其专有。我所拥有的是处理请求的中间件。当它从第三方应用程序重新识别请求作为登录请求时,它会创建授权链接并将其重定向到[identityserver] / connect / authorize,这是授权端点。然后服务器应该给我回jwt令牌,我会处理。无论如何身份服务器给我错误,当我查看日志文件时,我可以看到failureReason="STATUS_CODE"。但是Response.Redirect()设置了状态代码302 ,这应该没问题,应该不是吗?

客户端设置得很好。我正在使用Implicit流程。但是,对于AuthorizationCode或ClientCredentials,我将错误页面发送给我:消息:客户端应用程序未知或未经授权。状态代码204.

中间件代码段:

            string url = $"{context.Request.Scheme}://{context.Request.Host}";
            DiscoveryClient discoveryClient = new DiscoveryClient("https://localhost:44300/");
            DiscoveryResponse doc = await discoveryClient.GetAsync();

            AuthorizeRequest authorizeRequest = new AuthorizeRequest(doc.AuthorizeEndpoint);
            string authorizeUrl = authorizeRequest.CreateAuthorizeUrl(
                clientId: "zendesk",
                responseType: "id_token token",
                scope: "openid email profile",
                redirectUri: $"{url}/zendesk/authenticated",
                state: Base64Url.Encode(returnTo.ToBytes()));

            context.Response.Redirect(authorizeUrl);

            return;

重定向链接:

https://localhost:44300/connect/authorize?client_id=zendesk&response_type=id_token+token&scope=openid+email+profile&redirect_uri=https%3A%2F%2Flocalhost%3A44327%2Fzendesk%2Fauthenticated&state=[64encodedValue]

结果链接:

https://localhost:44327/zendesk/authenticated#error=invalid_request&state=[64encodedValue]

感谢任何提示,我在这里已经走到了尽头。

2 个答案:

答案 0 :(得分:0)

我有另一个包含有用信息的日志:

Nonce required for implicit and hybrid flow with openid scope
{
...
,
"SubjectId": "unknown",
"ResponseType": "id_token token",
"ResponseMode": "form_post",
"Flow": "Implicit",
"RequestedScopes": "openid email profile",
"State": "...",
"Raw": {
"client_id": "...",
"response_type": "id_token token",
"scope": "openid email profile",
"redirect_uri": "...",
"state": "...",
"response_mode": "form_post"
}

我决定使用其他流量。

答案 1 :(得分:0)

在/ authorize请求中添加nonce参数。

OpenId Connect Standard称它是可选的,但IdentityServer3将其作为必需参数。 -