本文整理汇总了Java中org.springframework.social.oauth2.OAuth2Parameters类的典型用法代码示例。如果您正苦于以下问题:Java OAuth2Parameters类的具体用法?Java OAuth2Parameters怎么用?Java OAuth2Parameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OAuth2Parameters类属于org.springframework.social.oauth2包,在下文中一共展示了OAuth2Parameters类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepare
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
@Override
public CredentialFlowState prepare(final String connectorId, final URI baseUrl, final URI returnUrl) {
final OAuth2CredentialFlowState.Builder flowState = new OAuth2CredentialFlowState.Builder().returnUrl(returnUrl)
.providerId(id);
final OAuth2Parameters parameters = new OAuth2Parameters();
final String callbackUrl = callbackUrlFor(baseUrl, EMPTY);
parameters.setRedirectUri(callbackUrl);
final String scope = connectionFactory.getScope();
parameters.setScope(scope);
final String stateKey = connectionFactory.generateState();
flowState.key(stateKey);
parameters.add("state", stateKey);
final OAuth2Operations oauthOperations = connectionFactory.getOAuthOperations();
final String redirectUrl = oauthOperations.buildAuthorizeUrl(parameters);
flowState.redirectUrl(redirectUrl);
flowState.connectorId(connectorId);
return flowState.build();
}
示例2: prepare
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
@Override
public CredentialFlowState prepare(final URI baseUrl, final URI returnUrl) {
final OAuth2CredentialFlowState.Builder flowState = new OAuth2CredentialFlowState.Builder().returnUrl(returnUrl)
.providerId(id);
final OAuth2Parameters parameters = new OAuth2Parameters();
final String callbackUrl = callbackUrlFor(baseUrl, EMPTY);
parameters.setRedirectUri(callbackUrl);
final String scope = connectionFactory.getScope();
parameters.setScope(scope);
final String stateKey = connectionFactory.generateState();
flowState.key(stateKey);
parameters.add("state", stateKey);
final OAuth2Operations oauthOperations = connectionFactory.getOAuthOperations();
final String redirectUrl = oauthOperations.buildAuthorizeUrl(parameters);
flowState.redirectUrl(redirectUrl);
return flowState.build();
}
示例3: getAuthorisationUrls
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
@Override
public AuthUrlPair getAuthorisationUrls(Channel channel, String callbackUrl)
{
ParameterCheck.mandatory("channel", channel);
if (!ID.equals(channel.getChannelType().getId()))
{
throw new IllegalArgumentException("Invalid channel type: " + channel.getChannelType().getId());
}
NodeRef channelRef = channel.getNodeRef();
StringBuilder authStateBuilder = new StringBuilder(channelRef.getStoreRef().getProtocol()).append('.').append(
channelRef.getStoreRef().getIdentifier()).append('.').append(channelRef.getId());
OAuth2Operations oauthOperations = publishingHelper.getConnectionFactory().getOAuthOperations();
OAuth2Parameters params = new OAuth2Parameters();
params.setRedirectUri(redirectUri);
params.setScope("publish_stream,offline_access,user_photos,user_videos");
params.setState(authStateBuilder.toString());
String authRequestUrl = oauthOperations.buildAuthorizeUrl(GrantType.IMPLICIT_GRANT, params);
return new AuthUrlPair(authRequestUrl, redirectUri);
}
示例4: getAuthenticateUrl
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
public String getAuthenticateUrl(String state)
{
String authenticateUrl = null;
if (state != null)
{
/*
* When we change to spring social 1.0.2 OAuth2Parameters will need to be updated OAuth2Parameters parameters = new
* OAuth2Parameters(); parameters.setRedirectUri(REDIRECT_URI); parameters.setScope(SCOPE); parameters.setState(state);
*/
MultiValueMap<String, String> additionalParameters = new LinkedMultiValueMap<String, String>(1);
additionalParameters.add("access_type", "offline");
OAuth2Parameters parameters = new OAuth2Parameters(GoogleDocsConstants.REDIRECT_URI, GoogleDocsConstants.SCOPE, state, additionalParameters);
parameters.getAdditionalParameters();
authenticateUrl = connectionFactory.getOAuthOperations().buildAuthenticateUrl(GrantType.AUTHORIZATION_CODE, parameters);
}
log.debug("Authentication URL: " + authenticateUrl);
return authenticateUrl;
}
示例5: buildOAuth2Url
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
private String buildOAuth2Url(OAuth2ConnectionFactory<?> connectionFactory, NativeWebRequest request,
MultiValueMap<String, String> additionalParameters) {
OAuth2Operations oauthOperations = connectionFactory.getOAuthOperations();
String defaultScope = connectionFactory.getScope();
OAuth2Parameters parameters = getOAuth2Parameters(request, defaultScope, additionalParameters);
String state = connectionFactory.generateState();
parameters.add("state", state);
sessionStrategy.setAttribute(request, OAUTH2_STATE_ATTRIBUTE, state);
return oauthOperations.buildAuthenticateUrl(parameters);
}
示例6: getOAuth2Parameters
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
private OAuth2Parameters getOAuth2Parameters(NativeWebRequest request, String defaultScope,
MultiValueMap<String, String> additionalParameters) {
OAuth2Parameters parameters = new OAuth2Parameters(additionalParameters);
parameters.putAll(getRequestParameters(request, "scope"));
parameters.setRedirectUri(callbackUrl(request));
String scope = request.getParameter("scope");
if (scope != null) {
parameters.setScope(scope);
} else if (defaultScope != null) {
parameters.setScope(defaultScope);
}
return parameters;
}
示例7: shouldAcquireOAuth2Credentials
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
@Test
public void shouldAcquireOAuth2Credentials() {
final OAuth2ConnectionFactory<?> oauth2 = mock(OAuth2ConnectionFactory.class);
@SuppressWarnings("unchecked")
final Applicator<AccessGrant> applicator = mock(Applicator.class);
when(locator.providerWithId("providerId"))
.thenReturn(new OAuth2CredentialProvider<>("providerId", oauth2, applicator));
when(oauth2.getScope()).thenReturn("scope");
when(oauth2.generateState()).thenReturn("state-token");
final OAuth2Operations operations = mock(OAuth2Operations.class);
when(oauth2.getOAuthOperations()).thenReturn(operations);
final ArgumentCaptor<OAuth2Parameters> parameters = ArgumentCaptor.forClass(OAuth2Parameters.class);
when(operations.buildAuthorizeUrl(parameters.capture())).thenReturn("https://provider.io/oauth/authorize");
final AcquisitionFlow acquisition = credentials.acquire("providerId", URI.create("https://syndesis.io/api/v1/"),
URI.create("/ui#state"));
final CredentialFlowState expectedFlowState = new OAuth2CredentialFlowState.Builder().key("state-token")
.providerId("providerId").redirectUrl("https://provider.io/oauth/authorize")
.returnUrl(URI.create("/ui#state")).build();
final AcquisitionFlow expected = new AcquisitionFlow.Builder().type(Type.OAUTH2)
.redirectUrl("https://provider.io/oauth/authorize").state(expectedFlowState).build();
assertThat(acquisition).isEqualTo(expected);
final OAuth2Parameters capturedParameters = parameters.getValue();
assertThat(capturedParameters.getRedirectUri()).isEqualTo("https://syndesis.io/api/v1/credentials/callback");
assertThat(capturedParameters.getScope()).isEqualTo("scope");
assertThat(capturedParameters.getState()).isEqualTo("state-token");
}
示例8: getAuthenticationURL
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
/**
* API for getting the Authentication URL for Alfresco CMIS Server using Oauth.
*
* @param clientKey {@link String}
* @param secretKey {@link String}
* @param redirectURL {@link String}
* @return authenticationURL.
*/
public String getAuthenticationURL(String clientKey, String secretKey, String redirectURL) {
LOGGER.info("Inside get Authentication URL method");
AlfrescoConnectionFactory connectionFactory = new AlfrescoConnectionFactory(clientKey, secretKey);
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.setRedirectUri(redirectURL);
parameters.setScope(Alfresco.DEFAULT_SCOPE);
return connectionFactory.getOAuthOperations().buildAuthenticateUrl(GrantType.AUTHORIZATION_CODE, parameters);
}
示例9: getSession
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的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;
}
示例10: init
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
@PostConstruct
public void init() {
authUrl = (useSsl ? baseUrlSecure : baseUrl) + "/googleplus/authenticate";
oAuthParams = new OAuth2Parameters();
oAuthParams.setRedirectUri(authUrl);
oAuthParams.setScope("https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.moments.write");
}
示例11: main
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
public static void main(String[] args) {
String secret = "<secret>";
String id = "<id>";
OAuth2Parameters oAuthParams = new OAuth2Parameters();
oAuthParams.setRedirectUri("<https-url>/googleplus/authenticate");
oAuthParams.setScope("https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.moments.write");
oAuthParams.put("access_type", Lists.newArrayList("offline"));
GooglePlusFactory factory = new GooglePlusFactory(id, secret);
// Uncomment parts of the code below to simulate the whole flow
// 1. Get the redirect url
// 2. Open the url in the browser, authenticate, and copy the authorization code from the reidrected url
// 3. Paste the code and exchange it for tokens.
// 4. Copy the tokens and use it for getApi(..)
// String url = factory.getOAuthOperations().buildAuthenticateUrl(oAuthParams);
// System.out.println(url);
// AccessGrant grant = factory.getOAuthOperations().exchangeForAccess("<code>", oAuthParams.getRedirectUri(), null);
// System.out.println(grant.getAccessToken());
// System.out.println(grant.getRefreshToken());
// Plus plus = factory.getApi("<token>");
// Person person = plus.getPeopleOperations().get("me");
// System.out.println(person.getName().getFamilyName());
}
示例12: getTokenMap
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
/**
* API for getting the token map generated after successful authentication on the Alfresco CMIS Server.
*
* @param clientKey {@link String}
* @param secretKey {@link String}
* @param redirectURL {@link String}
* @return tokenMap
* @throws DCMAApplicationException if any error or exception occurs.
*/
public Map<String, String> getTokenMap(String clientKey, String secretKey, String redirectURL) throws DCMAApplicationException {
LOGGER.info("Inside get token map method");
Map<String, String> map = new HashMap<String, String>();
String host = ICommonConstants.EMPTY_STRING;
String portString = ICommonConstants.EMPTY_STRING;
String callbackPath = ICommonConstants.EMPTY_STRING;
String[] splittedRedirectURL = redirectURL.split(ICommonConstants.FORWARD_SLASH + ICommonConstants.FORWARD_SLASH);
if (splittedRedirectURL.length > 1) {
String string = redirectURL.split(ICommonConstants.FORWARD_SLASH + ICommonConstants.FORWARD_SLASH)[1];
String[] splittedString = string.split(ICommonConstants.COLON);
if (splittedString.length > 1) {
host = splittedString[0];
String restURL = splittedString[1];
String[] splittedRestURL = restURL.split(ICommonConstants.FORWARD_SLASH);
if (splittedRestURL.length > 1) {
portString = splittedRestURL[0];
callbackPath = splittedRestURL[1];
}
}
}
LOGGER.info("Host address:" + host);
LOGGER.info("Port address:" + portString);
LOGGER.info("CallbackPath:" + callbackPath);
if (host == null || host.isEmpty() || portString == null || portString.isEmpty() || callbackPath == null
|| callbackPath.isEmpty()) {
throw new DCMAApplicationException("Invalid redirect URL provided for processing.");
}
int port = 8080;
try {
port = Integer.valueOf(portString);
} catch (NumberFormatException numberFormatException) {
LOGGER.error("Invalid port specified in the redirect URL.");
throw new DCMAApplicationException("Invalid port specified in redirect URL.");
}
VerificationCodeReceiver receiver = new LocalServerReceiver(host, port, callbackPath);
try {
receiver.getRedirectUri();
AlfrescoConnectionFactory connectionFactory = new AlfrescoConnectionFactory(clientKey, secretKey);
String code = receiver.waitForCode();
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.setRedirectUri(redirectURL);
parameters.setScope(Alfresco.DEFAULT_SCOPE);
AccessGrant accessGrant = connectionFactory.getOAuthOperations().exchangeForAccess(code, redirectURL, parameters);
map.put(CMISProperties.CMIS_REFRESH_TOKEN.getPropertyKey(), accessGrant.getRefreshToken());
} catch (Exception exception) {
LOGGER.error("Error occur while starting up the jetty server.");
throw new DCMAApplicationException("Error occur while setting the jetty server", exception);
} finally {
try {
receiver.stop();
} catch (Exception e) {
LOGGER.info("Error in stopping jetty server");
}
}
return map;
}
示例13: buildAuthenticateUrl
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
@Override
public String buildAuthenticateUrl(GrantType grantType, OAuth2Parameters parameters) {
if (redirectUri != null) parameters.setRedirectUri(redirectUri);
return super.buildAuthenticateUrl(grantType, parameters);
}
示例14: buildAuthorizeUrl
import org.springframework.social.oauth2.OAuth2Parameters; //导入依赖的package包/类
@Override
public String buildAuthorizeUrl(GrantType grantType, OAuth2Parameters parameters) {
if (redirectUri != null) parameters.setRedirectUri(redirectUri);
return super.buildAuthorizeUrl(grantType, parameters);
}