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


Java OAuth2Parameters类代码示例

本文整理汇总了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();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:27,代码来源:OAuth2CredentialProvider.java

示例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();
}
 
开发者ID:syndesisio,项目名称:syndesis-rest,代码行数:25,代码来源:OAuth2CredentialProvider.java

示例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);
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:21,代码来源:FacebookChannelType.java

示例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;
}
 
开发者ID:Pluies,项目名称:Alfresco-Google-docs-plugin,代码行数:25,代码来源:GoogleDocsServiceImpl.java

示例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);
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:11,代码来源:ConnectSupport.java

示例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;
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:14,代码来源:ConnectSupport.java

示例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");
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:32,代码来源:CredentialsTest.java

示例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);
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:19,代码来源:AlfrescoCMISOAuth.java

示例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;
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:34,代码来源:OAuthCMISSession.java

示例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");
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:8,代码来源:GooglePlusController.java

示例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());
    }
 
开发者ID:Glamdring,项目名称:google-plus-java-api,代码行数:28,代码来源:ManualTest.java

示例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;
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:75,代码来源:AlfrescoCMISOAuth.java

示例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);
}
 
开发者ID:alex-bretet,项目名称:cloudstreetmarket.com,代码行数:6,代码来源:YahooOAuth2Template.java

示例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);
}
 
开发者ID:alex-bretet,项目名称:cloudstreetmarket.com,代码行数:6,代码来源:YahooOAuth2Template.java


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