本文整理汇总了Java中org.scribe.utils.OAuthEncoder类的典型用法代码示例。如果您正苦于以下问题:Java OAuthEncoder类的具体用法?Java OAuthEncoder怎么用?Java OAuthEncoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuthEncoder类属于org.scribe.utils包,在下文中一共展示了OAuthEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAccessTokenExtractor
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public AccessTokenExtractor getAccessTokenExtractor() {
return new AccessTokenExtractor() {
@Override
public Token extract(String response) {
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
Matcher matcher = Pattern.compile("\"access_token\" : \"([^&\"]+)\"").matcher(response);
if (matcher.find())
{
String token = OAuthEncoder.decode(matcher.group(1));
return new Token(token, "", response);
}
else
{
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
}
}
};
}
示例2: getAccessTokenExtractor
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public AccessTokenExtractor getAccessTokenExtractor() {
return new AccessTokenExtractor() {
@Override
public Token extract(String response) {
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
Matcher matcher = Pattern.compile("\"access_token\" : \"([^&\"]+)\"").matcher(response);
if (matcher.find())
{
String token = OAuthEncoder.decode(matcher.group(1));
return new Token(token, "", response);
}
else
{
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
}
}
};
}
示例3: getAccessTokenExtractor
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public AccessTokenExtractor getAccessTokenExtractor() {
return new AccessTokenExtractor() {
@Override
public Token extract(String response) {
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
// We are not interested in access_token - we and the JWT encrypted token
// Matcher matcher = Pattern.compile("\"access_token\" : \"([^&\"]+)\"").matcher(response);
Matcher matcher = Pattern.compile("\"id_token\" : \"([^&\"]+)\"").matcher(response);
if (matcher.find()) {
String token = OAuthEncoder.decode(matcher.group(1));
return new Token(token, "", response);
} else {
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
}
}
};
}
示例4: getAuthorizationUrl
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback.") ;
if (config.hasScope())
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(),
OAuthEncoder.encode(config.getCallback()),
OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(),
OAuthEncoder.encode(config.getCallback()));
}
}
示例5: getAccessTokenExtractor
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new AccessTokenExtractor()
{
@Override
public Token extract( String response )
{
Preconditions.checkEmptyString( response, "Response body is incorrect. Can't extract a token from an empty string" );
Matcher matcher = Pattern.compile( "\"access_token\" : \"([^&\"]+)\"" ).matcher( response );
if ( matcher.find() )
{
String token = OAuthEncoder.decode( matcher.group( 1 ) );
return new Token( token, "", response );
}
else
{
throw new OAuthException( "Response body is incorrect. Can't extract a token from this: '" + response + "'", null );
}
}
};
}
示例6: getAuthorizationUrl
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public String getAuthorizationUrl( OAuthConfig config )
{
// Append scope if present
if ( config.hasScope() )
{
return String.format( SCOPED_AUTHORIZE_URL, config.getApiKey(),
OAuthEncoder.encode( config.getCallback() ),
OAuthEncoder.encode( config.getScope() ) );
}
else
{
return String.format( AUTHORIZE_URL, config.getApiKey(),
OAuthEncoder.encode( config.getCallback() ) );
}
}
示例7: getAuthorizationUrl
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public String getAuthorizationUrl( OAuthConfig config )
{
if ( config.hasScope() )
{
return String.format( SCOPED_AUTHORIZATION_URL,
config.getApiKey(),
OAuthEncoder.encode( config.getCallback() ),
OAuthEncoder.encode( config.getScope() ) );
}
else
{
return String.format( AUTHORIZATION_URL,
config.getApiKey(),
OAuthEncoder.encode( config.getCallback() ) );
}
}
示例8: getAccessTokenExtractor
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public AccessTokenExtractor getAccessTokenExtractor() {
return new AccessTokenExtractor() {
@Override
public Token extract(String response) {
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
Matcher matcher = Pattern.compile("\"access_token\" : \"([^&\"]+)\"").matcher(response);
if (matcher.find())
{
String token = OAuthEncoder.decode(matcher.group(1));
return new Token(token, "", response);
}
else
{
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
}
}
};
}
示例9: getAccessTokenExtractor
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
public AccessTokenExtractor getAccessTokenExtractor() {
return new AccessTokenExtractor() {
@Override
public Token extract(String response) {
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
Matcher matcher = Pattern.compile("\"access_token\" : \"([^&\"]+)\"").matcher(response);
if (matcher.find())
{
String token = OAuthEncoder.decode(matcher.group(1));
return new Token(token, "", response);
}
else
{
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
}
}
};
}
示例10: getAuthorizationUrl
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback for Instagram");
String uuid = ServerUtils.makeRandomString();
String aUrl = null;
if (config.hasScope())
{
aUrl = String.format(SCOPED_AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()),uuid,OAuthEncoder.encode(config.getScope()));
}
else
{
aUrl = String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()),uuid);
}
logger.info("Autorization URL: " + aUrl);
return aUrl;
}
示例11: extractToken
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
private static String extractToken(String name, String responseBody) {
try {
Preconditions.checkEmptyString(name, "name String is incorrect!");
Preconditions.checkEmptyString(responseBody, "Response body is incorrect. Can't extract a token from an empty string");
} catch (IllegalArgumentException e) {
throw new OAuthException(e.getMessage());
}
//{"access_token" : ""}
String REGEX = "\"%s\"\\s*:\\s*\"([^\"]+)\"";
REGEX = String.format(REGEX, name);
Matcher matcher = Pattern.compile(REGEX).matcher(responseBody);
if (matcher.find()) {
return OAuthEncoder.decode(matcher.group(1));
} else {
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + responseBody + "'", null);
}
}
示例12: testAuthorizationWithScopes
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Test
public void testAuthorizationWithScopes() {
String state = RandomStringUtils.randomAlphabetic(10);
String key = RandomStringUtils.randomAlphabetic(10);
String secret = RandomStringUtils.randomAlphabetic(10);
LinkedInApi20 api = new LinkedInApi20(state);
OAuthService service = new ServiceBuilder().provider(api).apiKey(key).apiSecret(secret)
.callback("http://localhost:4502/linkedin").scope("r_basicprofile,r_emailaddress")
.build();
String expected = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=" + key
+ "&state=" + state + "&redirect_uri=" + OAuthEncoder.encode("http://localhost:4502/linkedin")
+ "&scope=" + "r_basicprofile%2Cr_emailaddress";
assertEquals(expected, service.getAuthorizationUrl(null));
}
示例13: extract
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
private static String extract(String response, Pattern p) {
Matcher matcher = p.matcher(response);
if (matcher.find() && matcher.groupCount() >= 1) {
return OAuthEncoder.decode(matcher.group(1));
} else {
throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: " + response);
}
}
示例14: getAuthorizationUrl
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public String getAuthorizationUrl(OAuthConfig config) {
// Append scope if present
if (config.hasScope()) {
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(),
OAuthEncoder.encode(config.getCallback()),
OAuthEncoder.encode(config.getScope()));
} else {
return String.format(AUTHORIZE_URL, config.getApiKey(),
OAuthEncoder.encode(config.getCallback()));
}
}
示例15: getAuthorizationUrl
import org.scribe.utils.OAuthEncoder; //导入依赖的package包/类
@Override
public String getAuthorizationUrl(OAuthConfig config) {
if (config.hasScope()) {
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), githubState, OAuthEncoder.encode(config.getScope()));
} else {
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), githubState);
}
}