org.springframework.social.oauth1.OAuthToken Java Examples
The following examples show how to use
org.springframework.social.oauth1.OAuthToken.
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: 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 #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: 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 #4
Source File: CredentialModuleTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void shouldDeserializeFromJson() throws IOException { final String json = "{\"type\":\"OAUTH1\",\"accessToken\":{\"value\":\"access-token-value\",\"secret\":\"access-token-secret\"},\"token\":{\"value\":\"token-value\",\"secret\":\"token-secret\"},\"verifier\":\"verifier\",\"key\":\"key\",\"providerId\":\"twitter\",\"returnUrl\":\"https://localhost:4200/connections/create/configure-fields?state=create-connection&connectorId=twitter\"}"; final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new CredentialModule()); final OAuth1CredentialFlowState flowState = mapper.readerFor(CredentialFlowState.class).readValue(json); final OAuth1CredentialFlowState expected = new OAuth1CredentialFlowState.Builder() .accessToken(new OAuthToken("access-token-value", "access-token-secret")) .token(new OAuthToken("token-value", "token-secret")).verifier("verifier").key("key").providerId("twitter") .returnUrl(URI.create( "https://localhost:4200/connections/create/configure-fields?state=create-connection&connectorId=twitter")) .build(); assertThat(flowState).isEqualToIgnoringGivenFields(expected, "accessToken", "token"); assertThat(flowState.getAccessToken()).isEqualToComparingFieldByField(expected.getAccessToken()); assertThat(flowState.getToken()).isEqualToComparingFieldByField(expected.getToken()); }
Example #5
Source File: OAuth1CredentialProvider.java From syndesis with Apache License 2.0 | 5 votes |
private OAuth1CredentialProvider(final String id, final OAuth1ConnectionFactory<A> connectionFactory, final Applicator<OAuthToken> applicator, final boolean configured) { this.id = id; this.connectionFactory = connectionFactory; this.applicator = applicator; this.configured = configured; }
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: CredentialFlowStateTest.java From syndesis with Apache License 2.0 | 5 votes |
@Parameters(name = "{index}: {0}") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][] {{"OAUTH1", new OAuth1CredentialFlowState.Builder().key("key").providerId("providerId").redirectUrl("redirectUrl") .returnUrl(URI.create("return")).token(new OAuthToken("value", "secret")).verifier("verifier").build()}, {"OAUTH2", new OAuth2CredentialFlowState.Builder().key("key").providerId("providerId") .redirectUrl("redirectUrl").returnUrl(URI.create("return")).code("code").state("state").build()}}); }
Example #8
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 #9
Source File: OAuth1ApplicatorTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void shouldApplyTokens() { final SocialProperties properties = new SocialProperties() { // quick stub used in the test }; properties.setAppId("appId"); properties.setAppSecret("appSecret"); final OAuth1Applicator applicator = new OAuth1Applicator(properties); applicator.setAccessTokenSecretProperty("accessTokenSecretProperty"); applicator.setAccessTokenValueProperty("accessTokenValueProperty"); applicator.setConsumerKeyProperty("consumerKeyProperty"); applicator.setConsumerSecretProperty("consumerSecretProperty"); final Connection connection = new Connection.Builder().build(); final Connection result = applicator.applyTo(connection, new OAuthToken("tokenValue", "tokenSecret")); final Connection expected = new Connection.Builder() .putConfiguredProperty("accessTokenSecretProperty", "tokenSecret") .putConfiguredProperty("accessTokenValueProperty", "tokenValue") .putConfiguredProperty("consumerKeyProperty", "appId") .putConfiguredProperty("consumerSecretProperty", "appSecret").build(); assertThat(result).isEqualToIgnoringGivenFields(expected, "lastUpdated"); assertThat(result.getLastUpdated()).isPresent(); }
Example #10
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 #11
Source File: OAuth1CredentialProvider.java From syndesis with Apache License 2.0 | 5 votes |
@Override public CredentialFlowState finish(final CredentialFlowState givenFlowState, final URI baseUrl) { final OAuth1CredentialFlowState flowState = flowState(givenFlowState); final AuthorizedRequestToken requestToken = new AuthorizedRequestToken(flowState.getToken(), flowState.getVerifier()); final OAuthToken accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(requestToken, null); return new OAuth1CredentialFlowState.Builder().createFrom(flowState).accessToken(accessToken).build(); }
Example #12
Source File: CredentialModule.java From syndesis with Apache License 2.0 | 5 votes |
@Override public OAuthToken deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final Map<String, String> values = new HashMap<>(); String fieldName; while ((fieldName = p.nextFieldName()) != null) { final String nextValue = p.nextTextValue(); values.put(fieldName, nextValue); } return new OAuthToken(values.get("value"), values.get("secret")); }
Example #13
Source File: OAuth1Applicator.java From syndesis with Apache License 2.0 | 5 votes |
@Override public Connection applyTo(final Connection connection, final OAuthToken token) { final Connection.Builder mutableConnection = new Connection.Builder().createFrom(connection) .lastUpdated(new Date()); Applicator.applyProperty(mutableConnection, accessTokenValueProperty, token.getValue()); Applicator.applyProperty(mutableConnection, accessTokenSecretProperty, token.getSecret()); Applicator.applyProperty(mutableConnection, consumerKeyProperty, consumerKey); Applicator.applyProperty(mutableConnection, consumerSecretProperty, consumerSecret); return mutableConnection.build(); }
Example #14
Source File: SetupITCase.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void updateOAuthApp() { final OAuthApp twitter = new OAuthApp.Builder()// .putProperty("consumerKey", CLIENT_ID_PROPERTY)// .putProperty("consumerSecret", CLIENT_SECRET_PROPERTY)// .putConfiguredProperty("consumerKey", "test-id")// .putConfiguredProperty("consumerSecret", "test-secret")// .build(); http(HttpMethod.PUT, "/api/v1/setup/oauth-apps/twitter", twitter, null, tokenRule.validToken(), HttpStatus.NO_CONTENT); final ResponseEntity<OAuthResult> result = get("/api/v1/setup/oauth-apps", OAuthResult.class); final List<OAuthApp> apps = result.getBody().getItems(); assertThat(apps).isNotEmpty(); final OAuthApp updated = apps.stream().filter(x -> x.idEquals("twitter")).findFirst().get(); assertThat(updated.getId()).hasValue("twitter"); assertThat(updated.getName()).isEqualTo("Twitter"); assertThat(updated.getIcon()).startsWith("assets:"); assertThat(updated.propertyTaggedWith(Credentials.CLIENT_ID_TAG)).hasValue("test-id"); assertThat(updated.propertyTaggedWith(Credentials.CLIENT_SECRET_TAG)).hasValue("test-secret"); // Now that we have configured the app, we should be able to create the // connection factory. // The connection factory is setup async so we might need to wait a // little bit for it to register. given().ignoreExceptions().await().atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofSeconds(1)).until(() -> { final CredentialProvider twitterCredentialProvider = locator.providerWithId("twitter"); // preparing is something we could not do with a `null` // ConnectionFactory assertThat(twitterCredentialProvider).isNotNull().isInstanceOfSatisfying(OAuth1CredentialProvider.class, p -> { final Connection connection = new Connection.Builder().build(); final CredentialFlowState flowState = new OAuth1CredentialFlowState.Builder().accessToken(new OAuthToken("value", "secret")) .connectorId("connectorId").build(); final Connection appliedTo = p.applyTo(connection, flowState); // test that the updated values are used assertThat(appliedTo.getConfiguredProperties()).contains(entry("consumerKey", "test-id"), entry("consumerSecret", "test-secret")); }); return true; }); }
Example #15
Source File: OAuth1CredentialProvider.java From syndesis with Apache License 2.0 | 4 votes |
public OAuth1CredentialProvider(final String id, final OAuth1ConnectionFactory<A> connectionFactory, final Applicator<OAuthToken> applicator) { this(id, connectionFactory, applicator, true); }
Example #16
Source File: CredentialModule.java From syndesis with Apache License 2.0 | 4 votes |
public CredentialModule() { addDeserializer(OAuthToken.class, new OAuthTokenDeserializer()); }
Example #17
Source File: OAuth2CredentialFlowState.java From syndesis with Apache License 2.0 | 4 votes |
@Override public JavaType getOutputType(final TypeFactory typeFactory) { return typeFactory.constructType(OAuthToken.class); }
Example #18
Source File: OAuth1CredentialFlowState.java From syndesis with Apache License 2.0 | 4 votes |
@JsonDeserialize(converter = OAuthTokenConverter.class) OAuthToken getToken();
Example #19
Source File: OAuth1CredentialFlowState.java From syndesis with Apache License 2.0 | 4 votes |
@Override public JavaType getOutputType(final TypeFactory typeFactory) { return typeFactory.constructType(OAuthToken.class); }
Example #20
Source File: OAuth1CredentialFlowState.java From syndesis with Apache License 2.0 | 4 votes |
@Override public OAuthToken convert(final Map<String, String> value) { return new OAuthToken(value.get("value"), value.get("secret")); }
Example #21
Source File: OAuth1CredentialFlowState.java From syndesis with Apache License 2.0 | votes |
OAuthToken getAccessToken();