本文整理汇总了Java中org.springframework.social.connect.Connection.getApi方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.getApi方法的具体用法?Java Connection.getApi怎么用?Java Connection.getApi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.social.connect.Connection
的用法示例。
在下文中一共展示了Connection.getApi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
public void authenticate(Connection<?> connection) {
Facebook facebook = (Facebook) connection.getApi();
String [] fields = { "id", "name", "email", "first_name", "last_name" };
User userProfile = facebook.fetchObject("me", User.class, fields);
String username = userProfile.getName();
log.info("User Profile by facebook {} {} {}", userProfile.getFirstName(), userProfile.getLastName(), userProfile.getEmail());
Optional<io.osoon.domain.User> byEmail = userService.findByEmail(userProfile.getEmail());
io.osoon.domain.User osoonUser;
if (byEmail.isPresent()) {
osoonUser = byEmail.get();
} else {
io.osoon.domain.User newUser = io.osoon.domain.User.of(userProfile.getEmail(), username);
newUser.setImageUrl(connection.getImageUrl());
osoonUser = userService.saveOne(newUser);
}
OSoonUserDetails userDetails = new OSoonUserDetails(osoonUser);
RememberMeAuthenticationToken rememberMeToken = new RememberMeAuthenticationToken("osoon-remember-me", userDetails, null);
SecurityContextHolder.getContext().setAuthentication(rememberMeToken);
log.info("User {} {} {} connected.", userProfile.getFirstName(), userProfile.getLastName(), userProfile.getEmail());
}
示例2: facebook
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean(Facebook.class)
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Facebook facebook(ConnectionRepository repository) {
Connection<Facebook> connection = repository
.findPrimaryConnection(Facebook.class);
return connection != null ? connection.getApi() : null;
}
示例3: signIn
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public RedirectView signIn(@RequestParam("username") String username, @RequestParam("password") String password, NativeWebRequest request) {
try {
GarminConnectConnectionFactory connectionFactory = (GarminConnectConnectionFactory) this.connectionFactoryLocator.getConnectionFactory(GarminConnectConnection.PROVIDER_ID);
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
preSignIn(connectionFactory, parameters, request);
Connection<GarminConnect> connection = connectionFactory.createConnection(username, password);
GarminConnect api = connection.getApi();
// will throw exception if authentication fails
api.authenticate();
return handleSignIn(connection, connectionFactory, request);
} catch (Exception e) {
LOGGER.error("Exception while signing in to Garmin", e);
return redirect(URIBuilder.fromUri(signInUrl).queryParam("error", "provider").build().toString());
}
}
示例4: assertNewConnection
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
private void assertNewConnection(Connection<TestFacebookApi> connection) {
assertEquals("facebook", connection.getKey().getProviderId());
assertEquals("9", connection.getKey().getProviderUserId());
assertEquals("Keith Donald", connection.getDisplayName());
assertEquals("http://facebook.com/keith.donald", connection.getProfileUrl());
assertEquals("http://facebook.com/keith.donald/picture", connection.getImageUrl());
assertTrue(connection.test());
TestFacebookApi api = connection.getApi();
assertNotNull(api);
assertEquals("123456789", api.getAccessToken());
assertEquals("123456789", connection.createData().getAccessToken());
assertEquals("987654321", connection.createData().getRefreshToken());
}
示例5: assertTwitterConnection
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
private void assertTwitterConnection(Connection<TestTwitterApi> twitter) {
assertEquals(new ConnectionKey("twitter", "1"), twitter.getKey());
assertEquals("@kdonald", twitter.getDisplayName());
assertEquals("http://twitter.com/kdonald", twitter.getProfileUrl());
assertEquals("http://twitter.com/kdonald/picture", twitter.getImageUrl());
TestTwitterApi twitterApi = twitter.getApi();
assertEquals("123456789", twitterApi.getAccessToken());
assertEquals("987654321", twitterApi.getSecret());
twitter.sync();
assertEquals("http://twitter.com/kdonald/a_new_picture", twitter.getImageUrl());
}
示例6: assertFacebookConnection
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
private void assertFacebookConnection(Connection<TestFacebookApi> facebook) {
assertEquals(new ConnectionKey("facebook", "9"), facebook.getKey());
assertEquals(null, facebook.getDisplayName());
assertEquals(null, facebook.getProfileUrl());
assertEquals(null, facebook.getImageUrl());
TestFacebookApi facebookApi = facebook.getApi();
assertEquals("234567890", facebookApi.getAccessToken());
facebook.sync();
assertEquals("Keith Donald", facebook.getDisplayName());
assertEquals("http://facebook.com/keith.donald", facebook.getProfileUrl());
assertEquals("http://facebook.com/keith.donald/picture", facebook.getImageUrl());
}
示例7: getApi
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Override
public Discord getApi() {
if (log.isDebugEnabled()) {
log.debug("Getting API binding instance for Discord");
}
Connection<Discord> connection = usersConnectionRepository.createConnectionRepository(userIdSource.getUserId()).findPrimaryConnection(Discord.class);
if (log.isDebugEnabled() && connection == null) {
log.debug("No current connection; Returning default DiscordTemplate instance.");
}
return connection != null ? connection.getApi() : null;
}
示例8: google
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Google google(final ConnectionRepository repository) {
final Connection<Google> connection = repository
.findPrimaryConnection(Google.class);
return connection != null ? connection.getApi() : null;
}
示例9: gitHub
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public GitHub gitHub(ConnectionRepository repository) {
Connection<GitHub> connection = repository
.findPrimaryConnection(GitHub.class);
return connection != null ? connection.getApi() : null;
}
示例10: vkontakte
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public VKontakte vkontakte(ConnectionRepository repository) {
Connection<VKontakte> connection = repository.findPrimaryConnection(VKontakte.class);
if (connection != null) {
return connection.getApi();
}
return new VKontakteTemplate();
}
开发者ID:saladinkzn,项目名称:social-vkontakte-spring-boot-starter,代码行数:11,代码来源:VKontakteAutoConfiguration.java
示例11: twitter
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Twitter twitter(ConnectionRepository repository) {
Connection<Twitter> connection = repository
.findPrimaryConnection(Twitter.class);
if (connection != null) {
return connection.getApi();
}
return new TwitterTemplate(this.properties.getAppId(),
this.properties.getAppSecret());
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:TwitterAutoConfiguration.java
示例12: linkedin
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean(LinkedIn.class)
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public LinkedIn linkedin(ConnectionRepository repository) {
Connection<LinkedIn> connection = repository
.findPrimaryConnection(LinkedIn.class);
return connection != null ? connection.getApi() : null;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:LinkedInAutoConfiguration.java
示例13: getSession
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Override
public Map<String, String> getSession() throws DCMAApplicationException {
Map<String, String> map = new HashMap<String, String>();
Alfresco alfresco = null;
try {
validateClientKey(clientKey);
validateSecretKey(secretKey);
validateRefreshToken(refreshToken);
validateNetwork(network);
AlfrescoConnectionFactory connectionFactory = new AlfrescoConnectionFactory(clientKey, secretKey);
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.setScope(Alfresco.DEFAULT_SCOPE);
AccessGrant accessGrant = connectionFactory.getOAuthOperations().refreshAccess(refreshToken, null, parameters);
Connection<Alfresco> connection = connectionFactory.createConnection(accessGrant);
alfresco = connection.getApi();
map.put(CMISProperties.CMIS_REFRESH_TOKEN.getPropertyKey(), accessGrant.getRefreshToken());
if (alfresco != null) {
alfresco.getCMISSession(network);
} else {
throw new DCMAApplicationException("Unable to create alfresco instance");
}
// Get CMIS Session
} catch (HttpClientErrorException httpClientErrorException) {
throw new DCMAApplicationException(CMISExportConstant.CMIS_AUTHENTICATION_FAIL, httpClientErrorException);
} catch (ResourceAccessException resourceAccessException) {
throw new DCMAApplicationException(CMISExportConstant.CMIS_CONNECTION_FAIL, resourceAccessException);
} catch (CmisUnauthorizedException cmisUnauthorizedException) {
throw new DCMAApplicationException(CMISExportConstant.CMIS_UNAUTHORIZED_ACCESS, cmisUnauthorizedException);
}
return map;
}
示例14: assertNewConnection
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
private void assertNewConnection(Connection<TestFacebookApi> connection) {
assertEquals("facebook", connection.getKey().getProviderId());
assertEquals("9", connection.getKey().getProviderUserId());
assertEquals("Keith Donald", connection.getDisplayName());
assertEquals("http://facebook.com/keith.donald", connection.getProfileUrl());
assertEquals("http://facebook.com/keith.donald/picture", connection.getImageUrl());
assertTrue(connection.test());
TestFacebookApi api = connection.getApi();
assertNotNull(api);
assertEquals("123456789", api.getAccessToken());
assertEquals("123456789", connection.createData().getAccessToken());
assertEquals("987654321", connection.createData().getRefreshToken());
}
示例15: assertTwitterConnection
import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
private void assertTwitterConnection(Connection<TestTwitterApi> twitter) {
assertEquals(new ConnectionKey("twitter", "1"), twitter.getKey());
assertEquals("@kdonald", twitter.getDisplayName());
assertEquals("http://twitter.com/kdonald", twitter.getProfileUrl());
assertEquals("http://twitter.com/kdonald/picture", twitter.getImageUrl());
TestTwitterApi twitterApi = twitter.getApi();
assertEquals("123456789", twitterApi.getAccessToken());
assertEquals("987654321", twitterApi.getSecret());
twitter.sync();
assertEquals("http://twitter.com/kdonald/a_new_picture", twitter.getImageUrl());
}