diff --git a/src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java b/src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java index 4d6e2d0..7c52f4a 100644 --- a/src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java +++ b/src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java @@ -87,14 +87,18 @@ public class OAuthRestController implements InitializingBean, ApplicationContext /** * Verify access_token + *

+ * Ext. from CheckTokenEndpoint * - * @param value token + * @param value token + * @param clientId client_id * @return Map * @see org.springframework.security.oauth2.provider.endpoint.CheckTokenEndpoint + * @since 1.0 */ @RequestMapping(value = "/oauth/check_token", method = RequestMethod.POST) @ResponseBody - public Map checkToken(@RequestParam("token") String value) { + public Map checkToken(@RequestParam("token") String value, @RequestParam("client_id") String clientId) { OAuth2AccessToken token = resourceServerTokenServices.readAccessToken(value); if (token == null) { @@ -105,7 +109,16 @@ public class OAuthRestController implements InitializingBean, ApplicationContext throw new InvalidTokenException("Token has expired"); } + ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId); + if (clientDetails == null) { + throw new InvalidClientException("client_id was not recognised"); + } + OAuth2Authentication authentication = resourceServerTokenServices.loadAuthentication(token.getValue()); + final String authClientId = authentication.getOAuth2Request().getClientId(); + if (!clientId.equals(authClientId)) { + throw new InvalidClientException("Given client ID does not match authenticated client"); + } return accessTokenConverter.convertAccessToken(token, authentication); } diff --git a/src/main/webapp/WEB-INF/jsp/clientdetails/test_client.jsp b/src/main/webapp/WEB-INF/jsp/clientdetails/test_client.jsp index 6689e2a..fa91c3b 100644 --- a/src/main/webapp/WEB-INF/jsp/clientdetails/test_client.jsp +++ b/src/main/webapp/WEB-INF/jsp/clientdetails/test_client.jsp @@ -149,6 +149,25 @@ +

+
Verify [access_token]
+
+

输入access_token 后点击链接地址.

+ access_token: + +
+ +
+ + POST +
+
+
+
Back
@@ -174,6 +193,7 @@ $scope.password = "mobile"; //a temp value $scope.refreshToken = "1156ebfe-e303-4572-9fb5-4459a5d46610"; + $scope.accessToken = "e2996930-8398-44fd-8de5-7d1b1624ced7"; }]; diff --git a/src/main/webapp/resources/api/SOS_API-1.0.html b/src/main/webapp/resources/api/SOS_API-1.0.html index b4249ca..89c022a 100644 --- a/src/main/webapp/resources/api/SOS_API-1.0.html +++ b/src/main/webapp/resources/api/SOS_API-1.0.html @@ -34,6 +34,7 @@
  • 获取access_token (grant_type=client_credentials)
  • 获取access_token (Restful API)
  • +
  • 校验access_token
  • 刷新access_token (grant_type=refresh_token)
  • 获取当前用户信息 (ROLE_UNITY)
  • 获取当前用户信息 (ROLE_MOBILE)
  • @@ -418,6 +419,77 @@ +
    +

    校验access_token + public +

    + +

    校验, 检查access_token的有效性

    + + +

    返回