不支持Client_credentials授权类型

Restangular - Client_credentials grant type not supported?

本文关键字:授权 类型 credentials Client 不支持      更新时间:2023-09-26

下面的代码不起作用。授权类型为"client_credentials"。它返回状态为-1的空响应。API没问题。两个请求在邮差

上都可以正常工作。
function authentication(user) {
            return Restangular
                .all('token')
                .post('grant_type=client_credentials&client_id=' + APPLICATION.clientId + '&client_secret=' + 'XYZ',
                undefined, { 'Content-Type': 'application/x-www-form-urlencoded' });
        }

下面的代码与"password"授权类型完全匹配。

function authentication(user) {
            return Restangular
                .all('token')
                .post('grant_type=password&username=' + user.username + '&password=' + user.password + '&client_id=' + APPLICATION.clientId,
                undefined, { 'Content-Type': 'application/x-www-form-urlencoded' });
        }

怎么了?

看起来您正在使用相同的client_id来进行这些调用。第二个工作示例显示客户端是一个所谓的"公共客户端",因为它无需身份验证即可标识自己。您的第一个示例需要一个机密客户端,因为客户端需要在client_credentials流中验证自己。这两者不能混合,因此看起来您的客户端在授权服务器上注册为公共客户端,因此根据定义,它不能使用客户端凭据授予类型。