如何refesh oAuth2令牌+弹簧安全性

时间:2016-02-29 07:41:02

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

我已经使用oAuth2实现了Spring安全性。我希望在它到期之前刷新我们的访问令牌。请帮我刷新访问令牌的请求。

2 个答案:

答案 0 :(得分:0)

您可以向 oauth / token 发出POST请求,请参阅以下AngularJS代码段:

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

答案 1 :(得分:0)

oauth/token?grant_type=refresh_token&client_id=[id]&client_secret=[secret]&refresh_token=[your refresh token]

发送上述请求。您应该在请求中添加客户详细信息。