Spring Cloud OAuth2中访问/oauth/token报401 Unauthorized问题的解决

问题分析

在新建的Spring Cloud OAuth2项目中使用grant_type为password方式访问时报server_error。在postman中如下:

{
    "timestamp": "2021-01-16T10:26:53.052+00:00",
    "status": 401,
    "error": "Unauthorized",
    "message": "",
    "path": "/oauth/token"
}

如下图:
在这里插入图片描述

网上部分用户说使用grant_type=password获取access_token时可以不指定client_id和client_secret,就会报这个错误,消除这个错误的方式,就是不论grant_type的值是什么都需要在参数中指定client_id和client_secret

问题解决

在请求参数中加上client_id和client_secret,如下:
在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐