当前位置: 首页>>代码示例>>Java>>正文


Java OAuthToken类代码示例

本文整理汇总了Java中org.springframework.social.oauth1.OAuthToken的典型用法代码示例。如果您正苦于以下问题:Java OAuthToken类的具体用法?Java OAuthToken怎么用?Java OAuthToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OAuthToken类属于org.springframework.social.oauth1包,在下文中一共展示了OAuthToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldDeserializeFromJson

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@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());
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:21,代码来源:CredentialModuleTest.java

示例2: shouldApplyTokens

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@Test
public void shouldApplyTokens() {
    final SocialProperties properties = new SocialProperties() {
    };
    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();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:27,代码来源:OAuth1ApplicatorTest.java

示例3: printWelcome

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@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();
	}

      
   }
 
开发者ID:PacktPublishing,项目名称:Spring-MVC-Blueprints,代码行数:18,代码来源:SocialLogin.java

示例4: callback

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@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;
 }
 
开发者ID:PacktPublishing,项目名称:Spring-MVC-Blueprints,代码行数:18,代码来源:SocialLogin.java

示例5: authorization

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@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;
}
 
开发者ID:ttddyy,项目名称:evernote-rest-webapp,代码行数:26,代码来源:OAuthController.java

示例6: getConnectionFromChannelProps

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
public Connection<Flickr> getConnectionFromChannelProps(Map<QName,Serializable> channelProperties)
{
    Connection<Flickr> connection = null;
    String tokenValue = (String) encryptor.decrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, channelProperties
            .get(PublishingModel.PROP_OAUTH1_TOKEN_VALUE));
    String tokenSecret = (String) encryptor.decrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, channelProperties
            .get(PublishingModel.PROP_OAUTH1_TOKEN_SECRET));
    Boolean danceComplete = (Boolean) channelProperties.get(PublishingModel.PROP_AUTHORISATION_COMPLETE);
    
    if (danceComplete)
    {
        OAuthToken token = new OAuthToken(tokenValue, tokenSecret);
        connection = connectionFactory.createConnection(token);
    }
    return connection;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:17,代码来源:FlickrPublishingHelper.java

示例7: getConnectionForChannel

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
protected Connection<A> getConnectionForChannel(NodeRef channelNode)
{
    NodeService nodeService = getNodeService();
    Connection<A> connection = null;
    if (nodeService.exists(channelNode)
            && nodeService.hasAspect(channelNode, PublishingModel.ASPECT_OAUTH1_DELIVERY_CHANNEL))
    {
        String tokenValue = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, nodeService
                .getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_VALUE));
        String tokenSecret = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, nodeService
                .getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_SECRET));
        Boolean danceComplete = (Boolean) nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE);
        
        if (danceComplete)
        {
            OAuthToken token = new OAuthToken(tokenValue, tokenSecret);
            connection = connectionFactory.createConnection(token);
        }
    }
    return connection;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:22,代码来源:AbstractOAuth1ChannelType.java

示例8: getAuthorisationUrls

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@Override
public AuthUrlPair getAuthorisationUrls(Channel channel, String callbackUrl)
{
    ParameterCheck.mandatory("channel", channel);
    ParameterCheck.mandatory("callbackUrl", callbackUrl);
    if (!getId().equals(channel.getChannelType().getId()))
    {
        throw new IllegalArgumentException("Invalid channel type: " + channel.getChannelType().getId());
    }
    
    NodeService nodeService = getNodeService();
    OAuth1Operations oauthOperations = getOAuth1Operations();
    OAuthToken requestToken = oauthOperations.fetchRequestToken(callbackUrl, null);

    NodeRef channelNodeRef = channel.getNodeRef();
    nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_SECRET, 
            getEncryptor().encrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, requestToken.getSecret()));
    nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_VALUE, 
            getEncryptor().encrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, requestToken.getValue()));

    String authUrl = oauthOperations.buildAuthorizeUrl(requestToken.getValue(), getOAuth1Parameters(callbackUrl));
    return new AuthUrlPair(authUrl, callbackUrl);
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:24,代码来源:AbstractOAuth1ChannelType.java

示例9: testCreateOAuthToken

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@Test
public void testCreateOAuthToken() {

	EvernoteOAuth1Template template = new EvernoteOAuth1Template("key", "secret", EvernoteService.SANDBOX);
	MultiValueMap<String, String> response = new OAuth1Parameters();
	response.add("oauth_token", "test_token");
	response.add("oauth_token_secret", "test_secret");
	response.add("edam_shard", "test_shard");
	response.add("edam_userId", "test_userId");
	response.add("edam_expires", "test_expires");
	response.add("edam_noteStoreUrl", "test_noteStoreUrl");
	response.add("edam_webApiUrlPrefix", "test_webApiUrlPrefix");

	OAuthToken token = template.createOAuthToken("tokenValue", "tokenSecret", response);
	assertThat(token, instanceOf(EvernoteOAuthToken.class));

	EvernoteOAuthToken eToken = (EvernoteOAuthToken) token;
	assertThat(eToken.getValue(), is("test_token"));
	assertThat(eToken.getSecret(), is("test_secret"));
	assertThat(eToken.getEdamShard(), is("test_shard"));
	assertThat(eToken.getEdamUserId(), is("test_userId"));
	assertThat(eToken.getEdamExpires(), is("test_expires"));
	assertThat(eToken.getEdamNoteStoreUrl(), is("test_noteStoreUrl"));
	assertThat(eToken.getEdamWebApiUrlPrefix(), is("test_webApiUrlPrefix"));
}
 
开发者ID:ttddyy,项目名称:spring-social-evernote,代码行数:26,代码来源:EvernoteOAuth1TemplateTest.java

示例10: buildOAuth1Url

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
private String buildOAuth1Url(OAuth1ConnectionFactory<?> connectionFactory, NativeWebRequest request,
    MultiValueMap<String, String> additionalParameters) {
    OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();
    MultiValueMap<String, String> requestParameters = getRequestParameters(request);
    OAuth1Parameters parameters = getOAuth1Parameters(request, additionalParameters);
    parameters.putAll(requestParameters);
    if (oauthOperations.getVersion() == OAuth1Version.CORE_10) {
        parameters.setCallbackUrl(callbackUrl(request));
    }
    OAuthToken requestToken = fetchRequestToken(request, requestParameters, oauthOperations);
    sessionStrategy.setAttribute(request, OAUTH_TOKEN_ATTRIBUTE, requestToken);
    return buildOAuth1Url(oauthOperations, requestToken.getValue(), parameters);
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:14,代码来源:ConnectSupport.java

示例11: fetchRequestToken

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
private OAuthToken fetchRequestToken(NativeWebRequest request, MultiValueMap<String, String> requestParameters,
    OAuth1Operations oauthOperations) {
    if (oauthOperations.getVersion() == OAuth1Version.CORE_10_REVISION_A) {
        return oauthOperations.fetchRequestToken(callbackUrl(request), requestParameters);
    }
    return oauthOperations.fetchRequestToken(null, requestParameters);
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:8,代码来源:ConnectSupport.java

示例12: applyTo

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@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();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:13,代码来源:OAuth1Applicator.java

示例13: deserialize

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@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"));
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:13,代码来源:CredentialModule.java

示例14: finish

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@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();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:13,代码来源:OAuth1CredentialProvider.java

示例15: prepare

import org.springframework.social.oauth1.OAuthToken; //导入依赖的package包/类
@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();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:33,代码来源:OAuth1CredentialProvider.java


注:本文中的org.springframework.social.oauth1.OAuthToken类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。