private String token(OAuthClientRequest request, OAuthClient oAuthClient) throws Exception { String name = provider.getName(); if (name.equalsIgnoreCase("facebook") || name.equalsIgnoreCase("github")) { // application/x-www-form-urlencoded GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(request, GitHubTokenResponse.class); return oAuthResponse.getAccessToken(); } else { // JSON encoded OAuthJSONAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request, OAuthJSONAccessTokenResponse.class); return oAuthResponse.getAccessToken(); } }
/** * Retrieve access token, if needed, retrieve instance url, and set server host URL * {@inheritDoc} * @see org.apache.gobblin.writer.http.HttpWriter#onConnect(org.apache.http.HttpHost) */ @Override public void onConnect(URI serverHost) throws IOException { if (!StringUtils.isEmpty(accessToken)) { return; //No need to be called if accessToken is active. } try { getLog().info("Getting Oauth2 access token."); OAuthClientRequest request = OAuthClientRequest.tokenLocation(serverHost.toString()) .setGrantType(GrantType.PASSWORD) .setClientId(clientId) .setClientSecret(clientSecret) .setUsername(userId) .setPassword(password + securityToken).buildQueryMessage(); OAuthClient client = new OAuthClient(new URLConnectionClient()); OAuthJSONAccessTokenResponse response = client.accessToken(request, OAuth.HttpMethod.POST); accessToken = response.getAccessToken(); setCurServerHost(new URI(response.getParam("instance_url"))); } catch (OAuthProblemException e) { throw new NonTransientException("Error while authenticating with Oauth2", e); } catch (OAuthSystemException e) { throw new RuntimeException("Failed getting access token", e); } catch (URISyntaxException e) { throw new RuntimeException("Failed due to invalid instance url", e); } }
org.apache.oltu.oauth2.common.OAuth.HttpMethod.GET, OAuthResourceResponse.class); U.must(res.getResponseCode() == 200, "OAuth response error!"); Map<String, Object> auth = JSON.parseMap(res.getBody());
/** * @param token * @return */ @Override protected String getAuthenticateUser(AuthenticationContext context, Map<String, Object> jsonObject, OAuthClientResponse token) { return token.getParam(WindowsLiveOAuth2AuthenticatorConstants.USER_ID); }
.createCustomResponse(responseBody, c.getContentType(), responseCode, responseHeaders, responseClass);
@Override protected void init(InputStream body, String contentType, int responseCode, Map<String, List<String>> headers) throws OAuthProblemException { this.setBody(body); this.setContentType(contentType); this.setResponseCode(responseCode); this.setHeaders(headers); } }
protected void init(String body, String contentType, int responseCode, Map<String, List<String>> headers) throws OAuthProblemException { this.setBody(body); this.setContentType(contentType); this.setResponseCode(responseCode); this.setHeaders(headers); this.validate(); }
@Override public String getAccessToken() { return getParam(OAuth.OAUTH_ACCESS_TOKEN); }
public static OAuthClientResponse createJSONTokenResponse(String body, String contentType, int responseCode) throws OAuthProblemException { OAuthJSONAccessTokenResponse resp = new OAuthJSONAccessTokenResponse(); resp.init(body, contentType, responseCode); return resp; }
public static OAuthClientResponse createGitHubTokenResponse(String body, String contentType, int responseCode) throws OAuthProblemException { GitHubTokenResponse resp = new GitHubTokenResponse(); resp.init(body, contentType, responseCode); return resp; }
@Override protected void init(String body, String contentType, int responseCode, Map<String, List<String>> headers) throws OAuthProblemException { super.init(body, contentType, responseCode, headers); } }
@Override public String getTokenType() { return getParam(OAuth.OAUTH_TOKEN_TYPE); }
/** * Get Authenticated User * * @param token OAuth client response. * @return GUID of the authenticated user. */ @Override protected String getAuthenticateUser(AuthenticationContext context, Map<String, Object> jsonObject, OAuthClientResponse token) { return token.getParam(YahooOAuth2AuthenticatorConstants.USER_GUID); }
@Override protected void init(InputStream body, String contentType, int responseCode, Map<String, List<String>> headers) throws OAuthProblemException { this.setBody(body); this.setContentType(contentType); this.setResponseCode(responseCode); this.setHeaders(headers); } }
public static OAuthClientResponse createGitHubTokenResponse(String body, String contentType, int responseCode) throws OAuthProblemException { GitHubTokenResponse resp = new GitHubTokenResponse(); resp.init(body, contentType, responseCode); return resp; }
@Override protected void init(String body, String contentType, int responseCode, Map<String, List<String>> headers) throws OAuthProblemException { super.init(body, contentType, responseCode, headers); }
@Override public String getScope() { return getParam(OAuth.OAUTH_SCOPE); }
/** * @param token * @return */ @Override protected String getAuthenticateUser(AuthenticationContext context, Map<String, Object> jsonObject, OAuthClientResponse token) { return token.getParam(WindowsLiveOAuth2AuthenticatorConstants.USER_ID); }
/** * @param token * @return */ @Override protected String getAuthenticateUser(AuthenticationContext context, Map<String, Object> jsonObject, OAuthClientResponse token) { return token.getParam(WindowsLiveOAuth2AuthenticatorConstants.USER_ID); }
/** * Get Authenticated User * * @param token OAuth client response. * @return GUID of the authenticated user. */ @Override protected String getAuthenticateUser(AuthenticationContext context, Map<String, Object> jsonObject, OAuthClientResponse token) { return token.getParam(YahooOAuth2AuthenticatorConstants.USER_GUID); }