微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

oidc提供者访问UserInfo enpoint中提供的无效令牌

如何解决oidc提供者访问UserInfo enpoint中提供的无效令牌

我开始在节点js中将OAuth2服务器与oidc一起使用。 Github link

我的目标很简单,访问https:// myserver / me(这是UserInfo端点)。

在尝试学习如何使用服务器时,我也使用了本指南enter link description here 我发现可以通过向端点/ token发送请求来创建令牌。

在配置中,我添加了以下代码(完整的服务器代码如下):

{
    client_id: 'test_oauth_app',client_secret: 'super_secret',grant_types: ['client_credentials'],redirect_uris: [],response_types: [],}

在邮递员中,我可以通过此请求获取访问令牌

POST /token
Headers:
Content-Type: application/x-www-form-urlencoded
Authorization: Basic dGVzdF9vYXV0aF9hcHA6c3VwZXJfc2VjcmV0
Body:
grant_type=client_credentials&scopes=api1 

我得到这个答复:

{
    "access_token": "zdjmZo7_BQSIl4iK9IMcBbKffxGO-wQ3jLzzQXTlyws","expires_in": 600,"token_type": "Bearer"
}

当我通过/ token / introspection检查令牌时,我发现该令牌等于jti。 因此,我认为它实际上返回了token_id,因此我无法访问/ me端点。

这是我使用的整个服务器示例:

const { Provider } = require('oidc-provider');
const configuration = {
        features: {
                introspection: { enabled: true },clientCredentials: { enabled: true },userinfo: { enabled: true },jwtUserinfo: { enabled: true },},formats: {
            Accesstoken: 'jwt',clients: [{
            client_id: 'test_oauth_app',response_types: []
        }],scopes: ['api1']
};

const oidc = new Provider('http://localhost:3000',configuration);
oidc.proxy = true

// express/nodejs style application callback (req,res,next) for use with express apps,see /examples/express.js
oidc.callback

// koa application for use with koa apps,see /examples/koa.js
oidc.app

// or just expose a server standalone,see /examples/standalone.js
const server = oidc.listen(3000,() => {
  console.log('oidc-provider listening on port 3000,check https://localhost:3000/.well-kNown/openid-configuration');
});

该代理设置为true,因为我在重定向到该服务器的apache上设置了https。

我试图更改response_types,但是比之我需要在我的场景中不需要的redirect_uri。

这是我要像这样发布的请求:

POST /me
Headers:
Content-Type: application/json
Authorization: Bearer zdjmZo7_BQSIl4iK9IMcBbKffxGO-wQ3jLzzQXTlyws

响应:

{
    "error": "invalid_token","error_description": "invalid token provided"
}

有人有类似的问题吗?我发现了几乎相同的问题here 但不幸的是没有解决办法。

解决方法

如果有人遇到相同的问题。我能够解决它。

我没有足够的信息,也不知道client_credentials授予类型是什么。

它实际上并不授权用户,而是某些应用程序。因此,您没有有关用户的信息,因此无法通过userinfo端点获取有关用户的数据。

因此,如果要获取有关用户的信息,则可能要使用授权类型的授权代码。

我找到了一个页面,其中许多内容写得很清楚,所以如果您从 您可能想尝试一下OAuth服务器。 https://oauth2.thephpleague.com/authorization-server/auth-code-grant/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。