【问题标题】:How to refesh oAuth2 token + spring security如何刷新oAuth2令牌+弹簧安全
【发布时间】:2016-06-12 04:15:40
【问题描述】:

我已经使用 oAuth2 实现了 Spring 安全性。我想在访问令牌过期之前刷新它。请帮助我如何请求刷新我的访问令牌。

【问题讨论】:

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


    【解决方案1】:
    oauth/token?grant_type=refresh_token&client_id=[id]&client_secret=[secret]&refresh_token=[your refresh token]
    

    像上面一样发送请求。您应该在请求中添加客户详细信息。

    【讨论】:

    • 您好,我现在收到此异常 {"error":"server_error","error_description":"UserDetailsS​​ervice is required."}
    【解决方案2】:

    你可以向oauth/token发出POST请求,见AngularJS sn-p如下:

    function ajaxRefreshToken(refresh_token) {
            return $injector.get('$http')
                .post(
                    'oauth/token',
                    'grant_type=refresh_token&refresh_token=' + refresh_token,
                    {
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                        'Accept': 'application/json',
                        'Authorization': 'Basic ' + Base64.encode('***' + ':' + '***')
                    }
                });
        }
    

    或者,使用 cURL:

    curl -s -u $CLIENT_ID:$SECRET \
      'http://$HOST/oauth/token'  \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      --data 'grant_type=refresh_token&refresh_token='$REFRESH_TOKEN
    

    【讨论】:

    • 嗨@francesecou,我收到了这个请求 {"error":"unauthorized","error_description":"Full authentication is required to access this resource"}。
    • 您好,我现在收到此异常 {"error":"server_error","error_description":"UserDetailsS​​ervice is required."}
    • 你是用你的clientId和clientSecret替换这两个***吗?
    • @sdoxsee:是的,我在之前的评论中添加了一个 cURL 示例
    • @charnjeet-singh:请写完整的堆栈跟踪
    猜你喜欢
    • 2014-01-05
    • 1970-01-01
    • 2017-12-25
    • 2017-05-29
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    相关资源
    最近更新 更多