我正在研究一个我需要的项目,不仅需要进行身份验证,还要具有令牌的真实价值。Spring Security oAuth 2.0 UAA自动获取令牌值
我们有一个Spring启动应用程序与oAuth2.0 Spring Security,问题是我无法找到一个方法,每次我给它一个有效的标记。
在这一刻,我有一个post方法原料用Java编码,但必须有一个Spring Security实现,做类似以下内容:
- 第一次,它被调用时,它要求令牌并存储它。
- 以下时间会检查令牌是否已过期,如果已过期,则会请求新的令牌。
我在哪里可以找到它?
编辑
有2个不同春实例在我的项目:授权服务器 - 这是一个Cloud Foundry的UAA服务器 - 和资源服务器 - 这是一个要求令牌和编码的一个由我。
授权服务器在JWT版本中使用AuthorizationServerTokenServices,当资源服务器从那里获取令牌时,我希望它保留,不仅解码和使用,因为我需要将其发送到另一个服务器。
此外,我的应用程序不是一个Web应用程序,所以没有登录页面登录Facebook,我必须使用客户端凭证授予类型获取令牌。
在我的情况下,单点登录是不可能的,因为我必须使用它,而不是解码。
这是我目前实施:
public String obtainAccessToken() throws ClientProtocolException, IOException {
HttpClient httpclient = HttpClients.createDefault();
String userPass64 = new String("User and password");
HttpPost httppost = new HttpPost("localhost:8080/uaa/oauth/token?grant_type=client_credentials");
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httppost.setHeader("Authorization", "Basic " + userPass64);
//Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
String responseBody = EntityUtils.toString(response.getEntity());
ObjectMapper mapper = new ObjectMapper();
TokenMessage tokenMessage = mapper.readValue(responseBody, TokenMessage.class);
return tokenMessage.getAccess_token();
}
“authomatically” - 我喜欢你在那里做的:) – radoh
你是什么意思“我需要发送到另一台服务器。”?您是否试图从此服务器访问另一个受保护的资源? – raiyan