本文整理汇总了Java中org.springframework.social.connect.support.OAuth1ConnectionFactory类的典型用法代码示例。如果您正苦于以下问题:Java OAuth1ConnectionFactory类的具体用法?Java OAuth1ConnectionFactory怎么用?Java OAuth1ConnectionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuth1ConnectionFactory类属于org.springframework.social.connect.support包,在下文中一共展示了OAuth1ConnectionFactory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: oauth1Callback
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的package包/类
@GetMapping(value = "/signin/{providerId}", params = "oauth_token")
public RedirectView oauth1Callback(@PathVariable String providerId, NativeWebRequest request) {
try {
OAuth1ConnectionFactory<?> connectionFactory = (OAuth1ConnectionFactory<?>) connectionFactoryLocator
.getConnectionFactory(providerId);
Connection<?> connection = connectSupport.completeConnection(connectionFactory, request);
return handleSignIn(connection, connectionFactory, request);
} catch (Exception e) {
log.error("Exception while completing OAuth 1.0(a) connection: ", e);
return redirectOnError(providerId);
}
}
示例2: buildOAuthUrl
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的package包/类
/**
* Builds the provider URL to redirect the user to for connection authorization.
*
* @param connectionFactory the service provider's connection factory e.g. FacebookConnectionFactory
* @param request the current web request
* @param additionalParameters parameters to add to the authorization URL.
* @return the URL to redirect the user to for authorization
* @throws IllegalArgumentException if the connection factory is not OAuth1 based.
*/
public String buildOAuthUrl(ConnectionFactory<?> connectionFactory, NativeWebRequest request,
MultiValueMap<String, String> additionalParameters) {
if (connectionFactory instanceof OAuth1ConnectionFactory) {
return buildOAuth1Url((OAuth1ConnectionFactory<?>) connectionFactory, request, additionalParameters);
} else if (connectionFactory instanceof OAuth2ConnectionFactory) {
return buildOAuth2Url((OAuth2ConnectionFactory<?>) connectionFactory, request, additionalParameters);
} else {
throw new IllegalArgumentException("ConnectionFactory not supported");
}
}
示例3: buildOAuth1Url
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的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);
}
示例4: setup
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的package包/类
@Before
@SneakyThrows
public void setup() {
TenantProperties properties = new TenantProperties();
properties.setSocial(asList(
new TenantProperties.Social("twitter", "xxx", "yyy", DEFAULT_DOMAIN),
new TenantProperties.Social("facebook", "xxx", "yyy", DEFAULT_DOMAIN)
));
tenantPropertiesService.onRefresh("/config/tenants/"+ DEFAULT_TENANT + "/uaa/uaa.yml",
new ObjectMapper(new YAMLFactory()).writeValueAsString(properties));
MockitoAnnotations.initMocks(this);
SocialController socialController = new SocialController(socialService, providerSignInUtils,
connectionFactoryLocator, usersConnectionRepository, signInAdapter, connectSupport, sessionStrategy, socialConfigRepository);
this.restUserMockMvc = MockMvcBuilders.standaloneSetup(socialController)
.setControllerAdvice(exceptionTranslator)
.setMessageConverters(jacksonMessageConverter)
.build();
when(sessionStrategy.getAttribute(any(RequestAttributes.class), eq(ProviderSignInAttempt.SESSION_ATTRIBUTE)))
.thenReturn(providerSignInAttempt);
when(connection.fetchUserProfile())
.thenReturn(new UserProfile("id", "name", "fname", "lname", "email", "username"));
when(connection.createData()).thenReturn(
new ConnectionData("twitter", "providerUserId", "displayName", "profileUrl", "imageUrl", "", "secret",
"refreshToken", 1000L));
Mockito.<Connection<?>>when(connectSupport.completeConnection(any(OAuth1ConnectionFactory.class), any()))
.thenReturn(connection);
Mockito.<Connection<?>>when(connectSupport.completeConnection(any(OAuth2ConnectionFactory.class), any()))
.thenReturn(connection);
when(connectSupport.buildOAuthUrl(any(), any(), any())).thenReturn("SomeCallbackUrl");
Mockito.<Connection<?>>when(providerSignInAttempt.getConnection(any())).thenReturn(connection);
}
示例5: shouldCreateAcquisitionMethod
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的package包/类
@Test
public void shouldCreateAcquisitionMethod() {
@SuppressWarnings("unchecked")
final OAuth1CredentialProvider<?> oauth1 = new OAuth1CredentialProvider<>("provider1",
mock(OAuth1ConnectionFactory.class), mock(Applicator.class));
final AcquisitionMethod method1 = new AcquisitionMethod.Builder().description("provider1")
.label("provider1").icon("provider1").type(Type.OAUTH1).build();
assertThat(oauth1.acquisitionMethod()).isEqualTo(method1);
}
示例6: shouldFinishOAuth1Acquisition
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的package包/类
@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());
}
示例7: shouldCreateAcquisitionMethod
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的package包/类
@Test
public void shouldCreateAcquisitionMethod() {
@SuppressWarnings("unchecked")
final OAuth1CredentialProvider<?> oauth1 = new OAuth1CredentialProvider<>("provider1",
mock(OAuth1ConnectionFactory.class), mock(Applicator.class));
final ImmutableAcquisitionMethod method1 = new AcquisitionMethod.Builder().description("provider1")
.label("provider1").icon("provider1").type(Type.OAUTH1).build();
assertThat(oauth1.acquisitionMethod()).isEqualTo(method1);
}
示例8: OAuth1CredentialProvider
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的package包/类
public OAuth1CredentialProvider(final String id, final OAuth1ConnectionFactory<A> connectionFactory,
final Applicator<OAuthToken> applicator) {
this.id = id;
this.connectionFactory = connectionFactory;
this.applicator = applicator;
}
示例9: setConnectionFactory
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的package包/类
/**
* @param connectionFactory the connectionFactory to set
*/
public void setConnectionFactory(OAuth1ConnectionFactory<A> connectionFactory)
{
this.connectionFactory = connectionFactory;
}
示例10: completeConnection
import org.springframework.social.connect.support.OAuth1ConnectionFactory; //导入依赖的package包/类
/**
* Complete the connection to the OAuth1 provider.
*
* @param connectionFactory the service provider's connection factory e.g. FacebookConnectionFactory
* @param request the current web request
* @return a new connection to the service provider
*/
public Connection completeConnection(OAuth1ConnectionFactory<?> connectionFactory, NativeWebRequest request) {
String verifier = request.getParameter("oauth_verifier");
AuthorizedRequestToken requestToken = new AuthorizedRequestToken(extractCachedRequestToken(request), verifier);
OAuthToken accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(requestToken, null);
return connectionFactory.createConnection(accessToken);
}