public static HttpRequest newHttpRequest(GadgetContext context, RequestAuthenticationInfo authenticationInfo) throws GadgetException { return new HttpRequest(authenticationInfo.getHref()) .setSecurityToken(context.getToken()) .setOAuthArguments(new OAuthArguments(authenticationInfo)) .setOAuth2Arguments(new OAuth2Arguments(authenticationInfo)) .setAuthType(authenticationInfo.getAuthType()) .setContainer(context.getContainer()) .setGadget(context.getUrl()) .setIgnoreCache(context.getIgnoreCache()); }
@Test public void testWithOAuth2() throws Exception { String url = "http://example.org/oauth2"; String domain = "example.org"; setupProxyRequestMock(domain, url, false, -1, null, null); setupGadgetAdminMock(true); Map<String, String> options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); options.put("OAUTH_SCOPE", "scope1 scope2"); request.setAuthType(AuthType.OAUTH2); request.setOAuth2Arguments(new OAuth2Arguments(AuthType.OAUTH2, options)); options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); options.put("OAUTH_SCOPE", "scope1 scope2"); HttpRequest req = new HttpRequest(Uri.parse(url)) .setAuthType(AuthType.OAUTH2) .setGadget(Uri.parse("")) .setContainer("default") .setOAuth2Arguments(new OAuth2Arguments(AuthType.OAUTH2, options)); HttpResponse resp = new HttpResponseBuilder() .setResponseString("Hello") .create(); expect(pipeline.execute(req)).andReturn(resp); replay(); HttpResponse response = proxyHandler.fetch(request); verify(); assertEquals("Hello", response.getResponseAsString()); }
@Test public void testWithOAuth2() throws Exception { String url = "http://example.org/oauth2"; String domain = "example.org"; setupProxyRequestMock(domain, url, false, -1, null, null); setupGadgetAdminMock(true); Map<String, String> options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); options.put("OAUTH_SCOPE", "scope1 scope2"); request.setAuthType(AuthType.OAUTH2); request.setOAuth2Arguments(new OAuth2Arguments(AuthType.OAUTH2, options)); options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); options.put("OAUTH_SCOPE", "scope1 scope2"); HttpRequest req = new HttpRequest(Uri.parse(url)) .setAuthType(AuthType.OAUTH2) .setGadget(Uri.parse("")) .setContainer("default") .setOAuth2Arguments(new OAuth2Arguments(AuthType.OAUTH2, options)); HttpResponse resp = new HttpResponseBuilder() .setResponseString("Hello") .create(); expect(pipeline.execute(req)).andReturn(resp); replay(); HttpResponse response = proxyHandler.fetch(request); verify(); assertEquals("Hello", response.getResponseAsString()); }
OAuth2Arguments oauth2Args = new OAuth2Arguments(req.getAuthType(), authSettings); req.setOAuth2Arguments(oauth2Args); } else { Map<String, String> authSettings = getAuthSettings(requestItem);
req.setSecurityToken(extractAndValidateToken(request)); if (auth == AuthType.OAUTH2) { req.setOAuth2Arguments(new OAuth2Arguments(request)); } else { req.setOAuthArguments(new OAuthArguments(auth, request));
@Override public HttpRequest makeHttpRequest(Uri targetUri) throws GadgetException { HttpRequest req = super.makeHttpRequest(targetUri); // Set image params: req.setParam(Param.RESIZE_HEIGHT.getKey(), resizeHeight); req.setParam(Param.RESIZE_WIDTH.getKey(), resizeWidth); req.setParam(Param.RESIZE_QUALITY.getKey(), resizeQuality); req.setParam(Param.NO_EXPAND.getKey(), resizeNoExpand ? "1" : "0"); req.setParam(Param.RETURN_ORIGINAL_CONTENT_ON_ERROR.getKey(), returnOriginalContentOnError); req.setParam(Param.HTML_TAG_CONTEXT.getKey(), htmlTagContext); req.setSecurityToken(securityToken); req.setAuthType(authType); if(AuthType.OAUTH.equals(authType)) { req.setOAuthArguments(oauthArguments); } else if(AuthType.OAUTH2.equals(authType)) { req.setOAuth2Arguments(oauth2Arguments); } return req; }
.setIgnoreCache(context.getIgnoreCache()) .setOAuthArguments(oauthArgs) .setOAuth2Arguments(oauth2Args) .setAuthType(view.getAuthType()) .setSecurityToken(context.getToken())