private OAuthToken getAccessToken(String refreshToken) throws IOException { final String tokenUrl = String.format(ACCESS_TOKEN_URL, refreshToken, oAuthParams.getRedirectUri(), oAuthParams.getClientId(), oAuthParams.getClientSecret()); final WebRequest webRequest = new WebRequest(new URL(tokenUrl), HttpMethod.POST); final WebResponse webResponse = webClient.loadWebResponse(webRequest); if (webResponse.getStatusCode() != HttpStatus.SC_OK) { throw new IOException(String.format("Error getting access token: [%s: %s]", webResponse.getStatusCode(), webResponse.getStatusMessage())); } final long currentTime = System.currentTimeMillis(); final ObjectMapper mapper = new ObjectMapper(); final Map map = mapper.readValue(webResponse.getContentAsStream(), Map.class); final String accessToken = map.get("access_token").toString(); final Integer expiresIn = Integer.valueOf(map.get("expires_in").toString()); return new OAuthToken(refreshToken, accessToken, currentTime + TimeUnit.MILLISECONDS.convert(expiresIn, TimeUnit.SECONDS)); }
final OAuthSecureStorage secureStorage = oAuthParams.getSecureStorage(); if (secureStorage != null) { if (oAuthParams.getUserPassword() == null || oAuthParams.getUserPassword().isEmpty()) { throw new IllegalArgumentException("Missing password for LinkedIn authorization");
final String csrfId = String.valueOf(new SecureRandom().nextLong()); final String encodedRedirectUri = URLEncoder.encode(oAuthParams.getRedirectUri(), "UTF-8"); final OAuthScope[] scopes = oAuthParams.getScopes(); url = String.format(AUTHORIZATION_URL, oAuthParams.getClientId(), csrfId, encodedRedirectUri); } else { url = String.format(AUTHORIZATION_URL_WITH_SCOPE, oAuthParams.getClientId(), csrfId, builder.toString(), encodedRedirectUri); login.setText(oAuthParams.getUserName()); final HtmlPasswordInput password = loginForm.getInputByName("session_password"); password.setText(oAuthParams.getUserPassword()); final HtmlSubmitInput submitInput = (HtmlSubmitInput) loginForm.getElementsByAttribute("input", "type", "submit").get(0);
private static OAuthParams getOAuthParams(LinkedInConfiguration configuration) { return new OAuthParams(configuration.getUserName(), configuration.getUserPassword(), new CachingOAuthSecureStorage(configuration.getSecureStorage()), configuration.getClientId(), configuration.getClientSecret(), configuration.getRedirectUri(), configuration.getScopes()); }
} catch (IOException e) { throw new IllegalArgumentException( String.format("Error authorizing user %s: %s", oAuthParams.getUserName(), e.getMessage()), e);
private static OAuthParams getOAuthParams(LinkedInConfiguration configuration) { OAuthSecureStorage secureStorage = configuration.getSecureStorage(); if (secureStorage == null && !ObjectHelper.isEmpty(configuration.getAccessToken())) { secureStorage = new DefaultOAuthSecureStorage(configuration.getAccessToken(), configuration.getExpiryTime()); } return new OAuthParams(configuration.getUserName(), configuration.getUserPassword(), new CachingOAuthSecureStorage(secureStorage), configuration.getClientId(), configuration.getClientSecret(), configuration.getRedirectUri(), configuration.getScopes()); }