Okta 自省端点总是 returns false

Okta introspect endpoint always returns false

我正在尝试使用他们的 /introspect 端点验证新获得的 Okta OIDC 访问令牌,如 here 所述。我知道令牌很好,因为我是在验证后从浏览器的调试器中获取的。

不知道为什么,但端点总是返回 false — 即

{
    "active": false
}

我正在通过 Postman 尝试此操作。这是 Postman 生成的 curl 片段。

curl --location --request POST 'https://dev-359971.oktapreview.com/oauth2/v1/introspect' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'token=eyJr...yJPg' \
--data-urlencode 'client_id=0*****************7'

我在 Okta 的帮助中心 here 发现了同样的问题,但无论解决方案是什么,它从未发布过。

更新:

我应该提一下,我的 Okta 应用程序配置为 SPA,因此没有 client_secret。这就是为什么我的 cURL 调用中没有 Authorization header 的原因。根据 Okta 文档 here:

For public clients (such as single-page and mobile apps) that don't have a client_secret, you must include the client_id as a query parameter when calling the /introspect endpoint. Make sure that you aren't passing the Authorization header in the request.

这是我的开发帐户中的一个工作示例,我在其中使用默认的授权服务器。您需要发送 client_id 和 client_secret 并且在基本授权中配置它们是标准的 header:

视觉

下面突出显示了有关消息的关键事项:

CURL

如果我插入正确的值,这对我适用于命令行:

curl --request POST --user myclientid:myclientsecret \
https://dev-843469.oktapreview.com/oauth2/default/v1/introspect \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode token=XXX

API OAUTH 注册

您还需要在 Okta 中将 API 注册为内省客户端 - 如 Step 6 of my blog post

图书馆

任何体面的库都会为您完成大部分工作,例如 NodeJS Open Id Client:

Shout-out 感谢@GaryArcher 让我更接近答案。

问题是我未能指定一个 URI,该 URI 在 Okta 术语中被称为 “自定义授权服务器”.

意思是,当我应该使用 /oauth2/${authServerId}/v1/introspect 时,我使用 /oauth2/v1/introspect 作为端点——在我的例子中最终是 /oauth2/default/v1/introspect,因为我使用 default授权header.

Okta 文档 here 解释了如何编写您的基本 URI,其中针对 “Okta 作为您的应用程序的身份平台或 API" — 我的情况是:

for use cases where Okta is the authorization server for your resource server (for example, you want Okta to act as the user store for your application, but Okta is invisible to your users). This kind of authorization server we call a "Custom Authorization Server", and your base URL looks like this: https://${yourOktaDomain}/oauth2/${authServerId}

需要注意的是,如果您尝试使用 Postman collections that Okta offers 进行下载(我试过了),authServerId 不会包含在 URI 中。这就是让我失望的原因。

我希望这对其他人有帮助。