Java源码示例:org.springframework.social.oauth2.TokenStrategy

示例1
/**
 * 构造方法获取openId
 */
public QQImpl(String accessToken, String appId) {
	//access_token作为查询参数来携带。
	super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);

	this.appId = appId;

	String url = String.format(QQ_URL_GET_OPENID, accessToken);
	String result = getRestTemplate().getForObject(url, String.class);

	log.info("【QQImpl】 QQ_URL_GET_OPENID={} result={}", url, result);

	this.openId = StringUtils.substringBetween(result, "\"openid\":\"", "\"}");
}
 
示例2
public QQImpl(String accessToken, String appid) {
    //将token作为查询参数
    super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);
    this.appid = appid;

    //拼接成最终的openid的请求地址
    String url = String.format(URL_GET_OPENID, accessToken);
    String result = getRestTemplate().getForObject(url, String.class);
    this.openid = StringUtils.substringBetween(result, "\"openid\":\"", "\"}");
}
 
示例3
public QQImpl(String accessToken, String appId) {
    super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);
    this.appId = appId;
    String url = String.format(FebsConstant.GET_QQ_OPEN_ID_URL, accessToken);
    String result = this.getRestTemplate().getForObject(url, String.class);

    log.info(result);
    this.openId = StringUtils.substringBetween(result, "\"openid\":\"", "\"}");
}
 
示例4
@Override
public CredentialProvider create(final SocialProperties properties) {
    if (properties instanceof UnconfiguredProperties) {
        return new OAuth2CredentialProvider<>(OAUTH_2);
    }

    if (!(properties instanceof OAuth2ConnectorProperties)) {
        throw new IllegalArgumentException(String.format("Unsupported social properties instance - " +
                "expected properties of type %s, but found %s", OAuth2ConnectorProperties.class, properties.getClass()));
    }

    final OAuth2ConnectorProperties oauth2Properties = (OAuth2ConnectorProperties) properties;

    final String appId = oauth2Properties.getAppId();
    final String appSecret = oauth2Properties.getAppSecret();
    final String authorizationUrl = oauth2Properties.getAuthorizationUrl();
    final String authenticationUrl = oauth2Properties.getAuthenticationUrl();
    final String accessTokenUrl = oauth2Properties.getAccessTokenUrl();
    final boolean useParametersForClientCredentials = oauth2Properties.isUseParametersForClientCredentials();
    final TokenStrategy tokenStrategy = oauth2Properties.getTokenStrategy();
    final String scope = oauth2Properties.getScope();

    final OAuth2ServiceProvider<RestOperations> serviceProvider = new GenericOAuth2ServiceProvider(appId, appSecret, authorizationUrl,
        authenticationUrl, accessTokenUrl, useParametersForClientCredentials, tokenStrategy);

    final OAuth2ConnectionFactory<RestOperations> connectionFactory = new OAuth2ConnectionFactory<>(OAUTH_2, serviceProvider, null);
    connectionFactory.setScope(scope);

    final OAuth2Applicator applicator = new OAuth2Applicator(properties);
    applicator.setAccessTokenProperty("accessToken");
    applicator.setAccessTokenExpiresAtProperty("accessTokenExpiresAt");

    applicator.setRefreshTokenProperty("refreshToken");
    applicator.setClientIdProperty("clientId");
    applicator.setClientSecretProperty("clientSecret");

    return new OAuth2CredentialProvider<>(OAUTH_2, connectionFactory, applicator, oauth2Properties.getAdditionalQueryParameters());
}
 
示例5
public OAuth2ConnectorProperties(final Connector connector) {
    super(connector);

    accessTokenUrl = requiredProperty(connector, Credentials.ACCESS_TOKEN_URL_TAG);
    authenticationUrl = optionalProperty(connector, Credentials.AUTHENTICATION_URL_TAG).orElse(null);
    authorizationUrl = requiredProperty(connector, Credentials.AUTHORIZATION_URL_TAG);
    tokenStrategy = optionalProperty(connector, Credentials.TOKEN_STRATEGY_TAG).map(TokenStrategy::valueOf)
        .orElse(TokenStrategy.AUTHORIZATION_HEADER);
    useParameters = optionalProperty(connector, Credentials.AUTHORIZE_USING_PARAMETERS_TAG).map(Boolean::valueOf).orElse(false);
    scope = optionalProperty(connector, Credentials.SCOPE_TAG).orElse(null);

    additionalQueryParameters = optionalProperty(connector, Credentials.ADDITIONAL_QUERY_PARAMETERS_TAG)
        .map(params -> readJsonMap(params))
        .orElse(Collections.emptyMap());
}
 
示例6
public WechatImpl(String accessToken) {
    super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);
}
 
示例7
public WechatMpImpl(String accessToken) {
    super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);
}
 
示例8
public WeiXinImpl(String accessToken) {
    super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);
}
 
示例9
public WechatImpl(String accessToken) {
	super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);
	userOperations = new UserTemplate(restOperations(), accessToken);
}
 
示例10
public WeiXinImpl(String accessToken) {
    super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);
}
 
示例11
public TokenStrategy getTokenStrategy() {
    return tokenStrategy;
}
 
示例12
/**
 * Instantiates a new Qq.
 *
 * @param accessToken the access token
 * @param appId       the app id
 */
public QQImpl(String accessToken, String appId) {
	super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);

	this.appId = appId;

	String url = String.format(URL_GET_OPENID, accessToken);
	String result = getRestTemplate().getForObject(url, String.class);

	log.info("result={}", result);

	this.openId = StringUtils.substringBetween(result, "\"openid\":\"", "\"}");
}
 
示例13
/**
 * Instantiates a new Weixin.
 *
 * @param accessToken the access token
 */
public WeixinImpl(String accessToken) {
	super(accessToken, TokenStrategy.ACCESS_TOKEN_PARAMETER);
}