Commit c95b8117 authored by Quxl's avatar Quxl

x

parent c723c452
...@@ -7,11 +7,13 @@ import javax.servlet.http.HttpServletResponse; ...@@ -7,11 +7,13 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.oltu.oauth2.client.OAuthClient; import org.apache.oltu.oauth2.client.OAuthClient;
import org.apache.oltu.oauth2.client.URLConnectionClient; import org.apache.oltu.oauth2.client.URLConnectionClient;
import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest; import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
import org.apache.oltu.oauth2.client.response.OAuthAuthzResponse; import org.apache.oltu.oauth2.client.response.OAuthAuthzResponse;
import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse;
import org.apache.oltu.oauth2.client.response.OAuthResourceResponse;
import org.apache.oltu.oauth2.common.OAuth; import org.apache.oltu.oauth2.common.OAuth;
import org.apache.oltu.oauth2.common.exception.OAuthProblemException; import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
...@@ -54,4 +56,21 @@ public interface OAuthApi { ...@@ -54,4 +56,21 @@ public interface OAuthApi {
return token; return token;
} }
default String getResource(String method, String url, OAuthToken token) throws OAuthSystemException, OAuthProblemException {
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
String accessToken = token.getAccessToken();
OAuthClientRequest request = new OAuthBearerClientRequest(url).setAccessToken(accessToken).buildQueryMessage();
OAuthResourceResponse resourceResponse = oAuthClient.resource(request, method, OAuthResourceResponse.class);
String resBody = resourceResponse.getBody();
return resBody;
}
default String doGetResource(String url, OAuthToken token) throws OAuthSystemException, OAuthProblemException {
return this.getResource("GET", url, token);
}
default String doPostResource(String url, OAuthToken token) throws OAuthSystemException, OAuthProblemException {
return this.getResource("POST", url, token);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment