org.scribe.utils.Preconditions Java Examples
The following examples show how to use
org.scribe.utils.Preconditions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Google2Api.java From jpa-invoicer with The Unlicense | 6 votes |
@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); } } }; }
Example #2
Source File: HubicApi.java From swift-explorer with Apache License 2.0 | 6 votes |
@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())); } }
Example #3
Source File: WeiXinJsonTokenExtractor.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
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); } }
Example #4
Source File: SliTokenExtractor.java From secure-data-service with Apache License 2.0 | 5 votes |
@Override public Token extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); JsonParser parser = new JsonParser(); JsonObject json = parser.parse(response).getAsJsonObject(); if (json.has("error")) { throw new OAuthException(json.get("error_description").getAsString()); } return new Token(json.get("access_token").getAsString(), "", response); }
Example #5
Source File: SliTokenExtractor.java From secure-data-service with Apache License 2.0 | 5 votes |
@Override public Token extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); JsonNode root; try { root = mapper.readTree(response); JsonNode token = root.findValue("access_token"); return new Token(token.asText(), "", response); } catch (Exception e) { return null; } }
Example #6
Source File: SliApi.java From secure-data-service with Apache License 2.0 | 5 votes |
@Override public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback."); return String.format(REQUEST_TOKEN_FRAGMENT, apiUrl.toString(), config.getApiKey(), OAuthEncoder.encode(config.getCallback())); }
Example #7
Source File: ActionMapperRegistryImpl.java From APM with Apache License 2.0 | 4 votes |
@Override public Optional<MapperDescriptor> getMapper(String name) { Preconditions.checkNotNull(name, "Name cannot be null"); return Optional.ofNullable(mappers.get().get(name.trim().toLowerCase())); }
Example #8
Source File: HubicTokenExtractorImpl.java From swift-explorer with Apache License 2.0 | 4 votes |
public Token extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); AccessToken at = gson.fromJson(response, AccessToken.class); return new Token(at.getAccessToken(), EMPTY_SECRET, response); }
Example #9
Source File: HubicTokenExtractorImpl.java From swift-explorer with Apache License 2.0 | 4 votes |
public AccessToken getAccessToken (String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); AccessToken at = gson.fromJson(response, AccessToken.class); return at ; }
Example #10
Source File: SliApi.java From secure-data-service with Apache License 2.0 | 4 votes |
@Override public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback."); return String.format(authorizeUrl, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); }