且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法在同一应用程序中实现Stormpath表单登录/身份验证以及REST oAuth身份验证

更新时间:2023-11-22 16:56:58

问题可能与错误的请求有关.

The problem might be related to an incorrect request.

您可以在您的应用中尝试此代码吗?:

Is it possible for you to try this code in your app?:

 private boolean verify(String accessToken) throws OauthAuthenticationException {
     HttpRequest request = createRequestForOauth2AuthenticatedOperation(accessToken);
     AccessTokenResult result = Applications.oauthRequestAuthenticator(application)
        .authenticate(request);
     System.out.println(result.getAccount().getEmail() + " was successfully verified, you can allow your protect operation to continue");
     return true;
 }

 private HttpRequest createRequestForOauth2AuthenticatedOperation(String token) {
     try {
         Map<String, String[]> headers = new LinkedHashMap<String, String[]>();
         headers.put("Accept", new String[]{"application/json"});
         headers.put("Authorization", new String[]{"Bearer " + token});
         HttpRequest request = HttpRequests.method(HttpMethod.GET)
             .headers(headers)
             .build();
         return request;
     } catch (Exception e) {
         e.printStackTrace();
         return null;
     }
 }