org.pac4j.oauth.client.TwitterClient Java Examples
The following examples show how to use
org.pac4j.oauth.client.TwitterClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientActionTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Test public void verifyStartAuthentication() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setParameter(ClientAction.THEME, MY_THEME); mockRequest.setParameter(ClientAction.LOCALE, MY_LOCALE); mockRequest.setParameter(ClientAction.METHOD, MY_METHOD); final MockHttpSession mockSession = new MockHttpSession(); mockRequest.setSession(mockSession); final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class); when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest); final MockRequestContext mockRequestContext = new MockRequestContext(); mockRequestContext.setExternalContext(servletExternalContext); mockRequestContext.getFlowScope().put(ClientAction.SERVICE, new SimpleWebApplicationServiceImpl(MY_SERVICE)); final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET); final TwitterClient twitterClient = new TwitterClient(MY_KEY, MY_SECRET); final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient); final ClientAction action = new ClientAction(mock(CentralAuthenticationService.class), clients); final Event event = action.execute(mockRequestContext); assertEquals("error", event.getId()); assertEquals(MY_THEME, mockSession.getAttribute(ClientAction.THEME)); assertEquals(MY_LOCALE, mockSession.getAttribute(ClientAction.LOCALE)); assertEquals(MY_METHOD, mockSession.getAttribute(ClientAction.METHOD)); final MutableAttributeMap flowScope = mockRequestContext.getFlowScope(); assertTrue(((String) flowScope.get("FacebookClientUrl")) .startsWith("https://www.facebook.com/v2.2/dialog/oauth?client_id=my_key&redirect_uri=http%3A%2F%2Fcasserver%2Flogin%3F" + Clients.DEFAULT_CLIENT_NAME_PARAMETER + "%3DFacebookClient&state=")); assertEquals(MY_LOGIN_URL + "?" + Clients.DEFAULT_CLIENT_NAME_PARAMETER + "=TwitterClient&needs_client_redirection=true", flowScope.get("TwitterClientUrl")); }
Example #2
Source File: ClientActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testStartAuthentication() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setParameter(ClientAction.THEME, MY_THEME); mockRequest.setParameter(ClientAction.LOCALE, MY_LOCALE); mockRequest.setParameter(ClientAction.METHOD, MY_METHOD); final MockHttpSession mockSession = new MockHttpSession(); mockRequest.setSession(mockSession); final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class); when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest); final MockRequestContext mockRequestContext = new MockRequestContext(); mockRequestContext.setExternalContext(servletExternalContext); mockRequestContext.getFlowScope().put(ClientAction.SERVICE, new SimpleWebApplicationServiceImpl(MY_SERVICE)); final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET); final TwitterClient twitterClient = new TwitterClient(MY_KEY, MY_SECRET); final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient); final ClientAction action = new ClientAction(mock(CentralAuthenticationService.class), clients); final Event event = action.execute(mockRequestContext); assertEquals("error", event.getId()); assertEquals(MY_THEME, mockSession.getAttribute(ClientAction.THEME)); assertEquals(MY_LOCALE, mockSession.getAttribute(ClientAction.LOCALE)); assertEquals(MY_METHOD, mockSession.getAttribute(ClientAction.METHOD)); final MutableAttributeMap flowScope = mockRequestContext.getFlowScope(); assertTrue(((String) flowScope.get("FacebookClientUrl")) .startsWith("https://www.facebook.com/v2.2/dialog/oauth?client_id=my_key&redirect_uri=http%3A%2F%2Fcasserver%2Flogin%3F" + Clients.DEFAULT_CLIENT_NAME_PARAMETER + "%3DFacebookClient&state=")); assertEquals(MY_LOGIN_URL + "?" + Clients.DEFAULT_CLIENT_NAME_PARAMETER + "=TwitterClient&needs_client_redirection=true", flowScope.get("TwitterClientUrl")); }
Example #3
Source File: MavenArtifactNotifierWebappSecurityConfig.java From artifact-listener with Apache License 2.0 | 4 votes |
@Bean public TwitterClient twitterClient() { return new TwitterClient(configurer.getTwitterClientKey(), configurer.getTwitterClientSecret()); }