【问题标题】:jhipster oauth : How can i get the access_token via CURLjhipster oauth:如何通过 CURL 获取 access_token
【发布时间】:2015-03-31 21:53:12
【问题描述】:

我正在尝试使用 jhipster 工具来创建一个具有 oauth2 身份验证的新项目。项目示例工作正常,我可以使用 angularjs 界面登录,但不明白如何创建一个新用户,然后通过 Curl 命令行为这个新用户获取访问令牌。

感谢您的帮助

【问题讨论】:

    标签: angularjs curl spring-boot jhipster spring-security-oauth2


    【解决方案1】:

    第 1 步:注册用户。

    在http://localhost:8080/#/register注册用户并确保您可以通过网络界面登录。

    第 2 步:获取 OAuth2 令牌。

    获取 OAuth2 令牌所需的信息:

    1. OAuth2 客户端 ID(参见 application.yml)
    2. OAuth2 密钥(参见 application.yml)
    3. 用于注册新用户的用户名和密码 用户。
    4. 所需范围/秒

    然后,从服务器获取 OAuth 2 令牌:

    curl -X POST -vu client:secret http://localhost:8080/oauth/token -H "Accept: application/json" -d "username=username&password=password&grant_type=password&scope=read&client_id=clientid&client_secret=secret"
    

    .. 返回如下内容:

    {"access_token":"7916d326-0f7f-430f-8e32-c5135a121052","token_type":"bearer","refresh_token":"2c69ca58-a657-4780-b5d8-dc965d518e9e","expires_in":1037,"scope":"read"}
    

    第 3 步:在调用受保护资源时使用令牌:

    然后,必须在每次调用的标头中提供身份验证令牌:

    curl http://localhost:8080/app/rest/books -H "Authorization: Bearer 7916d326-0f7f-430f-8e32-c5135a121052"
    

    【讨论】:

    • Rori,我还有一个问题。现在我部署了一个服务器,我试图通过 ajax 从另一个接口(没有 jhipster 接口)获取 access_token 在这里你可以找到我的代码:jsfiddle.net/rpdyr97j/2你能帮帮我吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    • 2022-08-12
    • 2018-03-16
    • 2021-07-29
    • 1970-01-01
    • 2021-10-31
    相关资源
    最近更新 更多