【问题标题】:Spring OAuth2 - how to use the /oauth/authenticate endpoint?Spring OAuth2 - 如何使用 /oauth/authenticate 端点?
【发布时间】:2020-01-16 08:59:51
【问题描述】:

所以...我正在努力使用 Spring Boot OAuth2 来实现授权服务器。现在我收到 403 响应:

GET oauth/authorize?username=demo&password=demo&client_id=demo&response_type=token

看在上帝的份上,请求可以吗?我想从浏览器应用程序调用这个端点,它应该返回一个 access_token 和一个 refresh_token。为什么我需要为此提供一个 client_id?因为这个,我处于精神崩溃的边缘。您应该如何向此端点发送请求?

回复是:

{
  "timestamp": "2019-09-15T05:03:17.206+0000",
  "status": 403,
  "error": "Forbidden",
  "message": "Access Denied",
  "path": "/oauth/authorize"
}

编辑:

我的简化问题是这样的:@EnableAuthorizationServer 是否有一个端点,它是否像我想象的那样工作?您提供用户名和密码,它会返回 access_token 和 refresh_token。

【问题讨论】:

  • 使用直接使用令牌端点获取令牌的客户端凭据授权或最终用户密码授权。

标签: spring spring-boot spring-security oauth-2.0 spring-oauth2


【解决方案1】:

答案是肯定的,端点是 POST /oauth/token 带参数:

username -> YOUR_USERNAME
password -> YOUR_PASSWORD
grant_type -> password

clientId 和 secret 必须在 Authorization 标头中发送。

【讨论】:

  • 谢谢,这正是我要找的!
【解决方案2】:

ClientId 仅供用户访问服务器。所以首先创建一个服务器,然后尝试创建客户端:

在服务器中添加以下代码: @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients .inMemory() .withClient("ClientId") .secret("secret") .authorizedGrantTypes("authorization_code") .scopes("user_info") .autoApprove(true); }

客户端:在 spring 属性中正确添加您在服务器中保存的客户端 ID

【讨论】:

    猜你喜欢
    • 2019-07-09
    • 2015-03-20
    • 2015-06-11
    • 2015-04-22
    • 2015-01-01
    • 2021-12-12
    • 2017-05-16
    • 2017-03-26
    • 1970-01-01
    相关资源
    最近更新 更多