Search in sources :

Example 6 with OAuthException

use of org.scribe.exceptions.OAuthException in project openolat by klemens.

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);
            }
        }
    };
}
Also used : Matcher(java.util.regex.Matcher) OAuthException(org.scribe.exceptions.OAuthException) Token(org.scribe.model.Token) AccessTokenExtractor(org.scribe.extractors.AccessTokenExtractor)

Aggregations

OAuthException (org.scribe.exceptions.OAuthException)6 Matcher (java.util.regex.Matcher)4 Token (org.scribe.model.Token)4 AccessTokenExtractor (org.scribe.extractors.AccessTokenExtractor)3 IOException (java.io.IOException)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 OAuthRequest (org.scribe.model.OAuthRequest)2 Response (org.scribe.model.Response)2