use of org.scribe.exceptions.OAuthException in project webapp by elimu-ai.
the class Google2Api method getAccessTokenExtractor.
@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);
}
}
};
}
use of org.scribe.exceptions.OAuthException in project OpenOLAT by OpenOLAT.
the class Google2Api method getAccessTokenExtractor.
@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);
}
}
};
}
use of org.scribe.exceptions.OAuthException in project muikku by otavanopisto.
the class GoogleApi20ServiceImpl method getAccessToken.
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
request.addBodyParameter("grant_type", "authorization_code");
if (config.hasScope())
request.addBodyParameter(OAuthConstants.SCOPE, config.getScope());
Response response = request.send();
ObjectMapper objectMapper = new ObjectMapper();
String tokenJson;
try {
tokenJson = objectMapper.writeValueAsString(objectMapper.readTree(response.getBody()));
} catch (IOException e) {
throw new OAuthException("Invalid Token JSON", e);
}
return api.getAccessTokenExtractor().extract(tokenJson);
}
use of org.scribe.exceptions.OAuthException in project camel by apache.
the class JsonTokenExtractor method extract.
public Token extract(String response) {
Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String");
Matcher matcher = accessTokenPattern.matcher(response);
if (matcher.find()) {
return new Token(matcher.group(1), "", response);
} else {
throw new OAuthException("Cannot extract an acces token. Response was: " + response);
}
}
use of org.scribe.exceptions.OAuthException in project muikku by otavanopisto.
the class PyramusApi20ServiceImpl method getAccessToken.
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
request.addBodyParameter("grant_type", "authorization_code");
if (config.hasScope())
request.addBodyParameter(OAuthConstants.SCOPE, config.getScope());
Response response = request.send();
ObjectMapper objectMapper = new ObjectMapper();
String tokenJson;
try {
tokenJson = objectMapper.writeValueAsString(objectMapper.readTree(response.getBody()));
} catch (IOException e) {
throw new OAuthException("Invalid Token JSON", e);
}
return api.getAccessTokenExtractor().extract(tokenJson);
}
Aggregations