Search in sources :

Example 1 with AccessTokenExtractor

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

Example 2 with AccessTokenExtractor

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

Example 3 with AccessTokenExtractor

use of org.scribe.extractors.AccessTokenExtractor 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

Matcher (java.util.regex.Matcher)3 OAuthException (org.scribe.exceptions.OAuthException)3 AccessTokenExtractor (org.scribe.extractors.AccessTokenExtractor)3 Token (org.scribe.model.Token)3