首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在访问UserInfo enpoint的oidc提供程序中提供的无效令牌

在访问UserInfo enpoint的oidc提供程序中提供的无效令牌
EN

Stack Overflow用户
提问于 2020-10-31 19:32:55
回答 1查看 1.4K关注 0票数 1

我开始在节点js中使用带有oidc的OAuth2服务器。Github链接

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

在尝试学习如何使用服务器时,我还使用了这个指南在这里输入链接描述,在这里我发现可以通过向端点/token发送请求来创建令牌。

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

代码语言:javascript
复制
{
    client_id: 'test_oauth_app',
    client_secret: 'super_secret',
    grant_types: ['client_credentials'],
    redirect_uris: [],
    response_types: [],
}

在邮递员中,我能够通过这个请求得到我的access_token

代码语言:javascript
复制
POST /token
Headers:
Content-Type: application/x-www-form-urlencoded
Authorization: Basic dGVzdF9vYXV0aF9hcHA6c3VwZXJfc2VjcmV0
Body:
grant_type=client_credentials&scopes=api1 

我得到这个作为回应:

代码语言:javascript
复制
{
    "access_token": "zdjmZo7_BQSIl4iK9IMcBbKffxGO-wQ3jLzzQXTlyws",
    "expires_in": 600,
    "token_type": "Bearer"
}

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

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

代码语言:javascript
复制
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',
            client_secret: 'super_secret',
            grant_types: ['client_credentials'],
            redirect_uris: [],
            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是我在场景中不想要的。

以下是我试图以如下方式发布的请求:

代码语言:javascript
复制
POST /me
Headers:
Content-Type: application/json
Authorization: Bearer zdjmZo7_BQSIl4iK9IMcBbKffxGO-wQ3jLzzQXTlyws

答复:

代码语言:javascript
复制
{
    "error": "invalid_token",
    "error_description": "invalid token provided"
}

有人有类似的问题吗?我发现了几乎相同的问题,这里,但不幸的是,没有解决方案。

EN

回答 1

Stack Overflow用户

发布于 2020-11-02 21:12:35

万一有人遇到同样的问题。我解决了这个问题。

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

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

因此,如果您想获取有关用户的信息,可能需要使用授予类型authorization_code.。

我发现了一个页面,其中很多东西都写得很清楚,所以如果您从OAuth服务器开始,您可能想尝试一下。https://oauth2.thephpleague.com/authorization-server/auth-code-grant/

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64625660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档