private String generateCallbackForProvider( OAuthResponseParams responseParams, String callbackForProvider, String gadgetDomainCallback) throws OAuthRequestException { OAuthCallbackState state = new OAuthCallbackState(stateCrypter); state.setRealCallbackUrl(gadgetDomainCallback); UriBuilder callback = UriBuilder.parse(callbackForProvider); try { callback.addQueryParameter(OAuthCallbackServlet.CALLBACK_STATE_PARAM, state.getEncryptedState()); } catch (BlobCrypterException e) { throw new OAuthRequestException(OAuthError.UNKNOWN_PROBLEM, "Failure generating callback URL", e); } return callback.toString(); } }
private String generateCallbackForProvider( OAuthResponseParams responseParams, String callbackForProvider, String gadgetDomainCallback) throws OAuthRequestException { OAuthCallbackState state = new OAuthCallbackState(stateCrypter); state.setRealCallbackUrl(gadgetDomainCallback); UriBuilder callback = UriBuilder.parse(callbackForProvider); try { callback.addQueryParameter(OAuthCallbackServlet.CALLBACK_STATE_PARAM, state.getEncryptedState()); } catch (BlobCrypterException e) { throw new OAuthRequestException(OAuthError.UNKNOWN_PROBLEM, "Failure generating callback URL", e); } return callback.toString(); } }
private String generateCallbackForProvider( OAuthResponseParams responseParams, String callbackForProvider, String gadgetDomainCallback) throws OAuthRequestException { OAuthCallbackState state = new OAuthCallbackState(stateCrypter); state.setRealCallbackUrl(gadgetDomainCallback); UriBuilder callback = UriBuilder.parse(callbackForProvider); try { callback.addQueryParameter(OAuthCallbackServlet.CALLBACK_STATE_PARAM, state.getEncryptedState()); } catch (BlobCrypterException e) { throw new OAuthRequestException(OAuthError.UNKNOWN_PROBLEM, "Failure generating callback URL", e); } return callback.toString(); } }
@Test public void testServletWithCallback_noQueryParams() throws Exception { BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes()); OAuthCallbackState state = new OAuthCallbackState(crypter); OAuthCallbackServlet servlet = new OAuthCallbackServlet(); servlet.setStateCrypter(crypter); state.setRealCallbackUrl("http://www.example.com/callback"); expect(request.getParameter("cs")).andReturn(state.getEncryptedState()); expect(request.getQueryString()).andReturn("cs=foo"); replay(); servlet.doGet(this.request, this.recorder); verify(); assertEquals(302, this.recorder.getHttpStatusCode()); assertEquals("http://www.example.com/callback", this.recorder.getHeader("Location")); String cacheControl = this.recorder.getHeader("Cache-Control"); assertEquals("private,max-age=3600", cacheControl); } }
@Test public void testServletWithCallback_noQueryParams() throws Exception { BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes()); OAuthCallbackState state = new OAuthCallbackState(crypter); OAuthCallbackServlet servlet = new OAuthCallbackServlet(); servlet.setStateCrypter(crypter); state.setRealCallbackUrl("http://www.example.com/callback"); expect(request.getParameter("cs")).andReturn(state.getEncryptedState()); expect(request.getQueryString()).andReturn("cs=foo"); replay(); servlet.doGet(this.request, this.recorder); verify(); assertEquals(302, this.recorder.getHttpStatusCode()); assertEquals("http://www.example.com/callback", this.recorder.getHeader("Location")); String cacheControl = this.recorder.getHeader("Cache-Control"); assertEquals("private,max-age=3600", cacheControl); } }
@Test public void testServletWithCallback() throws Exception { BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes()); OAuthCallbackState state = new OAuthCallbackState(crypter); OAuthCallbackServlet servlet = new OAuthCallbackServlet(); servlet.setStateCrypter(crypter); state.setRealCallbackUrl("http://www.example.com/callback"); expect(request.getParameter("cs")).andReturn(state.getEncryptedState()); expect(request.getQueryString()).andReturn("cs=foo&bar=baz"); replay(); servlet.doGet(this.request, this.recorder); verify(); assertEquals(302, this.recorder.getHttpStatusCode()); assertEquals("http://www.example.com/callback?bar=baz", this.recorder.getHeader("Location")); String cacheControl = this.recorder.getHeader("Cache-Control"); assertEquals("private,max-age=3600", cacheControl); }
@Test public void testServletWithCallback() throws Exception { BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes()); OAuthCallbackState state = new OAuthCallbackState(crypter); OAuthCallbackServlet servlet = new OAuthCallbackServlet(); servlet.setStateCrypter(crypter); state.setRealCallbackUrl("http://www.example.com/callback"); expect(request.getParameter("cs")).andReturn(state.getEncryptedState()); expect(request.getQueryString()).andReturn("cs=foo&bar=baz"); replay(); servlet.doGet(this.request, this.recorder); verify(); assertEquals(302, this.recorder.getHttpStatusCode()); assertEquals("http://www.example.com/callback?bar=baz", this.recorder.getHeader("Location")); String cacheControl = this.recorder.getHeader("Cache-Control"); assertEquals("private,max-age=3600", cacheControl); }
@Test public void testServletWithCallback_noQueryParams() throws Exception { BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes()); OAuthCallbackState state = new OAuthCallbackState(crypter); OAuthCallbackServlet servlet = new OAuthCallbackServlet(); servlet.setStateCrypter(crypter); state.setRealCallbackUrl("http://www.example.com/callback"); expect(request.getParameter("cs")).andReturn(state.getEncryptedState()); expect(request.getQueryString()).andReturn("cs=foo"); replay(); servlet.doGet(this.request, this.recorder); verify(); assertEquals(302, this.recorder.getHttpStatusCode()); assertEquals("http://www.example.com/callback", this.recorder.getHeader("Location")); String cacheControl = this.recorder.getHeader("Cache-Control"); assertEquals("private,max-age=3600", cacheControl); } }
@Test public void testServletWithCallback() throws Exception { BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes()); OAuthCallbackState state = new OAuthCallbackState(crypter); OAuthCallbackServlet servlet = new OAuthCallbackServlet(); servlet.setStateCrypter(crypter); state.setRealCallbackUrl("http://www.example.com/callback"); expect(request.getParameter("cs")).andReturn(state.getEncryptedState()); expect(request.getQueryString()).andReturn("cs=foo&bar=baz"); replay(); servlet.doGet(this.request, this.recorder); verify(); assertEquals(302, this.recorder.getHttpStatusCode()); assertEquals("http://www.example.com/callback?bar=baz", this.recorder.getHeader("Location")); String cacheControl = this.recorder.getHeader("Cache-Control"); assertEquals("private,max-age=3600", cacheControl); }