org.springframework.social.oauth1.OAuth1Operations Java Examples
The following examples show how to use
org.springframework.social.oauth1.OAuth1Operations.
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: SocialLogin.java From Spring-MVC-Blueprints with MIT License | 6 votes |
@RequestMapping(value = "/twitterLogin") public void printWelcome(HttpServletResponse response,HttpServletRequest request) { TwitterConnectionFactory connectionFactoryTwitter = new TwitterConnectionFactory("<consumer id>","<consumer key>"); OAuth1Operations oauth1Operations = connectionFactoryTwitter.getOAuthOperations(); OAuthToken requestToken = oauth1Operations.fetchRequestToken("http://www.localhost:8080/ch08/erp/twitterAuthentication.html", null); String authorizeUrl = oauth1Operations.buildAuthorizeUrl(requestToken.getValue(), OAuth1Parameters.NONE); try { response.sendRedirect(authorizeUrl); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #2
Source File: SocialLogin.java From Spring-MVC-Blueprints with MIT License | 6 votes |
@RequestMapping(value = "/twitterAuthentication") public RedirectView callback(@RequestParam(value = "oauth_token") String oauthToken, @RequestParam(value = "oauth_verifier") String oauthVerifier) { TwitterConnectionFactory connectionFactoryTwitter = new TwitterConnectionFactory("<consumer id>","<consumer key>"); OAuth1Operations oauth1Operations = connectionFactoryTwitter.getOAuthOperations(); OAuthToken requestToken = oauth1Operations.fetchRequestToken("http://www.localhost:8080/ch08/erp/twitterAuthentication.html", null); RedirectView redirectView = new RedirectView(); redirectView.setContextRelative(true); OAuthToken accessToken = oauth1Operations.exchangeForAccessToken(new AuthorizedRequestToken(requestToken, oauthVerifier), OAuth1Parameters.NONE); if(accessToken.equals("<enter access token here>")){ redirectView.setUrl("/erp/paymentmodes.xml"); }else{ redirectView.setUrl("http://www.google.com"); } return redirectView; }
Example #3
Source File: OAuthController.java From evernote-rest-webapp with Apache License 2.0 | 6 votes |
@RequestMapping("/auth") public Map<String, String> authorization(@RequestParam String callbackUrl, @RequestParam(required = false) boolean preferRegistration, @RequestParam(required = false) boolean supportLinkedSandbox) { // obtain request token (temporal credential) final OAuth1Operations oauthOperations = this.evernoteConnectionFactory.getOAuthOperations(); final OAuthToken requestToken = oauthOperations.fetchRequestToken(callbackUrl, null); // no additional param // construct authorization url with callback url for client to redirect final OAuth1Parameters parameters = new OAuth1Parameters(); if (preferRegistration) { parameters.set("preferRegistration", "true"); // create account } if (supportLinkedSandbox) { parameters.set("supportLinkedSandbox", "true"); } final String authorizeUrl = oauthOperations.buildAuthorizeUrl(requestToken.getValue(), parameters); final Map<String, String> map = new HashMap<String, String>(); map.put("authorizeUrl", authorizeUrl); map.put("requestTokenValue", requestToken.getValue()); map.put("requestTokenSecret", requestToken.getSecret()); return map; }
Example #4
Source File: OAuth1CredentialProvider.java From syndesis with Apache License 2.0 | 5 votes |
@Override public CredentialFlowState prepare(final String connectorId, final URI baseUrl, final URI returnUrl) { final OAuth1CredentialFlowState.Builder flowState = new OAuth1CredentialFlowState.Builder().returnUrl(returnUrl) .providerId(id); final OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations(); final OAuth1Parameters parameters = new OAuth1Parameters(); final String stateKey = UUID.randomUUID().toString(); flowState.key(stateKey); final OAuthToken oAuthToken; final OAuth1Version oAuthVersion = oauthOperations.getVersion(); if (oAuthVersion == OAuth1Version.CORE_10) { parameters.setCallbackUrl(callbackUrlFor(baseUrl, EMPTY)); oAuthToken = oauthOperations.fetchRequestToken(null, null); } else if (oAuthVersion == OAuth1Version.CORE_10_REVISION_A) { oAuthToken = oauthOperations.fetchRequestToken(callbackUrlFor(baseUrl, EMPTY), null); } else { throw new IllegalStateException("Unsupported OAuth 1 version: " + oAuthVersion); } flowState.token(oAuthToken); final String redirectUrl = oauthOperations.buildAuthorizeUrl(oAuthToken.getValue(), parameters); flowState.redirectUrl(redirectUrl); flowState.connectorId(connectorId); return flowState.build(); }
Example #5
Source File: CredentialsTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void shouldFinishOAuth1Acquisition() { final OAuthToken token = new OAuthToken("value", "secret"); final OAuth1ConnectionFactory<?> oauth1 = mock(OAuth1ConnectionFactory.class); final OAuth1Applicator applicator = new OAuth1Applicator(properties); when(locator.providerWithId("providerId")) .thenReturn(new OAuth1CredentialProvider<>("providerId", oauth1, applicator)); final OAuth1Operations operations = mock(OAuth1Operations.class); when(oauth1.getOAuthOperations()).thenReturn(operations); final ArgumentCaptor<AuthorizedRequestToken> requestToken = ArgumentCaptor .forClass(AuthorizedRequestToken.class); final OAuthToken accessToken = new OAuthToken("tokenValue", "tokenSecret"); @SuppressWarnings({"unchecked", "rawtypes"}) final Class<MultiValueMap<String, String>> multimapType = (Class) MultiValueMap.class; when(operations.exchangeForAccessToken(requestToken.capture(), isNull(multimapType))).thenReturn(accessToken); applicator.setAccessTokenSecretProperty("accessTokenSecretProperty"); applicator.setAccessTokenValueProperty("accessTokenValueProperty"); applicator.setConsumerKeyProperty("consumerKeyProperty"); applicator.setConsumerSecretProperty("consumerSecretProperty"); final CredentialFlowState flowState = new OAuth1CredentialFlowState.Builder().providerId("providerId") .token(token).returnUrl(URI.create("/ui#state")).verifier("verifier").build(); final CredentialFlowState finalFlowState = credentials.finishAcquisition(flowState, URI.create("https://www.example.com")); final AuthorizedRequestToken capturedRequestToken = requestToken.getValue(); assertThat(capturedRequestToken.getValue()).isEqualTo("value"); assertThat(capturedRequestToken.getSecret()).isEqualTo("secret"); assertThat(capturedRequestToken.getVerifier()).isEqualTo("verifier"); assertThat(finalFlowState) .isEqualTo(new OAuth1CredentialFlowState.Builder().createFrom(flowState).accessToken(accessToken).build()); }
Example #6
Source File: OAuthController.java From evernote-rest-webapp with Apache License 2.0 | 5 votes |
@RequestMapping("/accessToken") public EvernoteOAuthToken obtainAccessToken(@RequestParam String oauthToken, @RequestParam String oauthVerifier, @RequestParam String requestTokenSecret) { final OAuthToken requestToken = new OAuthToken(oauthToken, requestTokenSecret); final AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(requestToken, oauthVerifier); final OAuth1Operations oAuth1Operations = this.evernoteConnectionFactory.getOAuthOperations(); // EvernoteOAuth1Operations final OAuthToken accessToken = oAuth1Operations.exchangeForAccessToken(authorizedRequestToken, null); // no additional param return (EvernoteOAuthToken) accessToken; }
Example #7
Source File: OAuthControllerIntegrationTest.java From evernote-rest-webapp with Apache License 2.0 | 5 votes |
@Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); EvernoteOAuth1Operations evernoteOAuth1Operations = (EvernoteOAuth1Operations) this.evernoteConnectionFactory.getOAuthOperations(); OAuth1Operations operations = evernoteOAuth1Operations.getSelectedOauth1Operations(); RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(operations, "restTemplate"); this.mockServer = MockRestServiceServer.createServer(restTemplate); }
Example #8
Source File: _CustomSocialUsersConnectionRepositoryIntTest.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 4 votes |
public OAuth1Operations getOAuthOperations() { return null; }