public OAuthProtocolException(int status, OAuthMessage reply) { String problem = OAuthUtil.getParameter(reply, OAuthProblemException.OAUTH_PROBLEM); if (problem == null) { throw new IllegalArgumentException("No problem reported for OAuthProtocolException"); } this.problemCode = problem; if (fatalProblems.contains(problem)) { startFromScratch = true; canRetry = false; canExtend = false; } else if (temporaryProblems.contains(problem)) { startFromScratch = false; canRetry = false; canExtend = false; } else if (extensionProblems.contains(problem)) { startFromScratch = false; canRetry = true; canExtend = true; } else { // fallback to status to figure out behavior if (status == HttpResponse.SC_UNAUTHORIZED) { startFromScratch = true; canRetry = true; } else { startFromScratch = false; canRetry = false; } canExtend = false; } }
accessor.accessToken = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN); accessor.tokenSecret = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET); accessorInfo.setSessionHandle(OAuthUtil.getParameter(reply, OAuthConstants.OAUTH_SESSION_HANDLE)); accessorInfo.setTokenExpireMillis(ACCESS_TOKEN_EXPIRE_UNKNOWN); if (OAuthUtil.getParameter(reply, OAuthConstants.OAUTH_EXPIRES_IN) != null) { try { int expireSecs = Integer.parseInt(OAuthUtil.getParameter(reply, OAuthConstants.OAUTH_EXPIRES_IN)); long expireMillis = fetcherConfig.getClock().currentTimeMillis() + expireSecs * 1000L;
public OAuthProtocolException(int status, OAuthMessage reply) { String problem = OAuthUtil.getParameter(reply, OAuthProblemException.OAUTH_PROBLEM); if (problem == null) { throw new IllegalArgumentException("No problem reported for OAuthProtocolException"); } this.problemCode = problem; if (fatalProblems.contains(problem)) { startFromScratch = true; canRetry = false; canExtend = false; } else if (temporaryProblems.contains(problem)) { startFromScratch = false; canRetry = false; canExtend = false; } else if (extensionProblems.contains(problem)) { startFromScratch = false; canRetry = true; canExtend = true; } else { // fallback to status to figure out behavior if (status == HttpResponse.SC_UNAUTHORIZED) { startFromScratch = true; canRetry = true; } else { startFromScratch = false; canRetry = false; } canExtend = false; } }
accessor.accessToken = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN); accessor.tokenSecret = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET); accessorInfo.setSessionHandle(OAuthUtil.getParameter(reply, OAuthConstants.OAUTH_SESSION_HANDLE)); accessorInfo.setTokenExpireMillis(ACCESS_TOKEN_EXPIRE_UNKNOWN); if (OAuthUtil.getParameter(reply, OAuthConstants.OAUTH_EXPIRES_IN) != null) { try { int expireSecs = Integer.parseInt(OAuthUtil.getParameter(reply, OAuthConstants.OAUTH_EXPIRES_IN)); long expireMillis = fetcherConfig.getClock().currentTimeMillis() + expireSecs * 1000;
public OAuthProtocolException(int status, OAuthMessage reply) { String problem = OAuthUtil.getParameter(reply, OAuthProblemException.OAUTH_PROBLEM); if (problem == null) { throw new IllegalArgumentException("No problem reported for OAuthProtocolException"); } this.problemCode = problem; if (fatalProblems.contains(problem)) { startFromScratch = true; canRetry = false; canExtend = false; } else if (temporaryProblems.contains(problem)) { startFromScratch = false; canRetry = false; canExtend = false; } else if (extensionProblems.contains(problem)) { startFromScratch = false; canRetry = true; canExtend = true; } else { // fallback to status to figure out behavior if (status == HttpResponse.SC_UNAUTHORIZED) { startFromScratch = true; canRetry = true; } else { startFromScratch = false; canRetry = false; } canExtend = false; } }
accessor.accessToken = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN); accessor.tokenSecret = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET); accessorInfo.setSessionHandle(OAuthUtil.getParameter(reply, OAuthConstants.OAUTH_SESSION_HANDLE)); accessorInfo.setTokenExpireMillis(ACCESS_TOKEN_EXPIRE_UNKNOWN); if (OAuthUtil.getParameter(reply, OAuthConstants.OAUTH_EXPIRES_IN) != null) { try { int expireSecs = Integer.parseInt(OAuthUtil.getParameter(reply, OAuthConstants.OAUTH_EXPIRES_IN)); long expireMillis = fetcherConfig.getClock().currentTimeMillis() + expireSecs * 1000L;
private void fetchRequestToken() throws OAuthRequestException, OAuthProtocolException { OAuthAccessor accessor = accessorInfo.getAccessor(); HttpRequest request = createRequestTokenRequest(accessor); List<Parameter> requestTokenParams = Lists.newArrayList(); addCallback(requestTokenParams); HttpRequest signed = sanitizeAndSign(request, requestTokenParams, true); OAuthMessage reply = sendOAuthMessage(signed); accessor.requestToken = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN); accessor.tokenSecret = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET); }
private void fetchRequestToken() throws OAuthRequestException, OAuthProtocolException { OAuthAccessor accessor = accessorInfo.getAccessor(); HttpRequest request = createRequestTokenRequest(accessor); List<Parameter> requestTokenParams = Lists.newArrayList(); addCallback(requestTokenParams); HttpRequest signed = sanitizeAndSign(request, requestTokenParams, true); OAuthMessage reply = sendOAuthMessage(signed); accessor.requestToken = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN); accessor.tokenSecret = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET); }
private void fetchRequestToken() throws OAuthRequestException, OAuthProtocolException { OAuthAccessor accessor = accessorInfo.getAccessor(); HttpRequest request = createRequestTokenRequest(accessor); List<Parameter> requestTokenParams = Lists.newArrayList(); addCallback(requestTokenParams); HttpRequest signed = sanitizeAndSign(request, requestTokenParams, true, this.accessorInfo.getConsumer().isOauthBodyHash()); OAuthMessage reply = sendOAuthMessage(signed); accessor.requestToken = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN); accessor.tokenSecret = OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET); }
/** * Sends OAuth request token and access token messages. */ private OAuthMessage sendOAuthMessage(HttpRequest request) throws OAuthRequestException, OAuthProtocolException { HttpResponse response = fetchFromServer(request); checkForProtocolProblem(response); OAuthMessage reply = new OAuthMessage(null, null, null); reply.addParameters(OAuth.decodeForm(response.getResponseAsString())); reply = parseAuthHeader(reply, response); if (OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN) == null) { throw new OAuthRequestException(OAuthError.MISSING_OAUTH_PARAMETER, OAuth.OAUTH_TOKEN); } if (OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET) == null) { throw new OAuthRequestException(OAuthError.MISSING_OAUTH_PARAMETER, OAuth.OAUTH_TOKEN_SECRET); } return reply; }
/** * Sends OAuth request token and access token messages. */ private OAuthMessage sendOAuthMessage(HttpRequest request) throws OAuthRequestException, OAuthProtocolException { HttpResponse response = fetchFromServer(request); checkForProtocolProblem(response); OAuthMessage reply = new OAuthMessage(null, null, null); reply.addParameters(OAuth.decodeForm(response.getResponseAsString())); reply = parseAuthHeader(reply, response); if (OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN) == null) { throw new OAuthRequestException(OAuthError.MISSING_OAUTH_PARAMETER, OAuth.OAUTH_TOKEN); } if (OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET) == null) { throw new OAuthRequestException(OAuthError.MISSING_OAUTH_PARAMETER, OAuth.OAUTH_TOKEN_SECRET); } return reply; }
/** * Sends OAuth request token and access token messages. */ private OAuthMessage sendOAuthMessage(HttpRequest request) throws OAuthRequestException, OAuthProtocolException { HttpResponse response = fetchFromServer(request); checkForProtocolProblem(response); OAuthMessage reply = new OAuthMessage(null, null, null); reply.addParameters(OAuth.decodeForm(response.getResponseAsString())); reply = parseAuthHeader(reply, response); if (OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN) == null) { throw new OAuthRequestException(OAuthError.MISSING_OAUTH_PARAMETER, OAuth.OAUTH_TOKEN); } if (OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET) == null) { throw new OAuthRequestException(OAuthError.MISSING_OAUTH_PARAMETER, OAuth.OAUTH_TOKEN_SECRET); } return reply; }
/** * Look for an OAuth protocol problem. For cases where no access token is in play * @param response * @throws OAuthProtocolException */ private void checkForProtocolProblem(HttpResponse response) throws OAuthProtocolException { if (couldBeFullOAuthError(response)) { // OK, might be OAuth related. OAuthMessage message = parseAuthHeader(null, response); if (OAuthUtil.getParameter(message, OAuthProblemException.OAUTH_PROBLEM) != null) { // SP reported extended error information throw new OAuthProtocolException(response.getHttpStatusCode(), message); } // No extended information, guess based on HTTP response code. if (response.getHttpStatusCode() == HttpResponse.SC_UNAUTHORIZED) { throw new OAuthProtocolException(response.getHttpStatusCode()); } } }
/** * Look for an OAuth protocol problem. For cases where no access token is in play * @param response * @throws OAuthProtocolException */ private void checkForProtocolProblem(HttpResponse response) throws OAuthProtocolException { if (couldBeFullOAuthError(response)) { // OK, might be OAuth related. OAuthMessage message = parseAuthHeader(null, response); if (OAuthUtil.getParameter(message, OAuthProblemException.OAUTH_PROBLEM) != null) { // SP reported extended error information throw new OAuthProtocolException(response.getHttpStatusCode(), message); } // No extended information, guess based on HTTP response code. if (response.getHttpStatusCode() == HttpResponse.SC_UNAUTHORIZED) { throw new OAuthProtocolException(response.getHttpStatusCode()); } } }
/** * Look for an OAuth protocol problem. For cases where no access token is in play * @param response * @throws OAuthProtocolException */ private void checkForProtocolProblem(HttpResponse response) throws OAuthProtocolException { if (couldBeFullOAuthError(response)) { // OK, might be OAuth related. OAuthMessage message = parseAuthHeader(null, response); if (OAuthUtil.getParameter(message, OAuthProblemException.OAUTH_PROBLEM) != null) { // SP reported extended error information throw new OAuthProtocolException(response.getHttpStatusCode(), message); } // No extended information, guess based on HTTP response code. if (response.getHttpStatusCode() == HttpResponse.SC_UNAUTHORIZED) { throw new OAuthProtocolException(response.getHttpStatusCode()); } } }
if (!"foo".equals(OAuthUtil.getParameter(info.message, "oauth_magic"))) { throw new RuntimeException("no oauth_trusted=foo parameter"); if (!"bar".equals(OAuthUtil.getParameter(info.message, "opensocial_magic"))) { throw new RuntimeException("no opensocial_trusted=foo parameter"); if (!"quux".equals(OAuthUtil.getParameter(info.message, "xoauth_magic"))) { throw new RuntimeException("no xoauth_magic=quux parameter"); OAuthUtil.getParameter(info.message, "opensocial_owner_id"))) { throw new RuntimeException("opensocial_owner_id should be overridden");
if (!"foo".equals(OAuthUtil.getParameter(info.message, "oauth_magic"))) { throw new RuntimeException("no oauth_trusted=foo parameter"); if (!"bar".equals(OAuthUtil.getParameter(info.message, "opensocial_magic"))) { throw new RuntimeException("no opensocial_trusted=foo parameter"); if (!"quux".equals(OAuthUtil.getParameter(info.message, "xoauth_magic"))) { throw new RuntimeException("no xoauth_magic=quux parameter"); OAuthUtil.getParameter(info.message, "opensocial_owner_id"))) { throw new RuntimeException("opensocial_owner_id should be overridden");
if (!"foo".equals(OAuthUtil.getParameter(info.message, "oauth_magic"))) { throw new RuntimeException("no oauth_trusted=foo parameter"); if (!"bar".equals(OAuthUtil.getParameter(info.message, "opensocial_magic"))) { throw new RuntimeException("no opensocial_trusted=foo parameter"); if (!"quux".equals(OAuthUtil.getParameter(info.message, "xoauth_magic"))) { throw new RuntimeException("no xoauth_magic=quux parameter"); OAuthUtil.getParameter(info.message, "opensocial_owner_id"))) { throw new RuntimeException("opensocial_owner_id should be overridden");