service = new OAuth10aService(api, oauthConfig); } else { DefaultApi20 api = new DefaultApi20() { service = new OAuth20Service(api, oauthConfig);
service.signRequest((OAuth1AccessToken) token, oauthRequest);
public void doInBackground() { try { if (service.getVersion() == "1.0") { OAuth10aService oAuth10aService = (OAuth10aService) service; requestToken = oAuth10aService.getRequestToken(); authorizeUrl = oAuth10aService.getAuthorizationUrl((OAuth1RequestToken) requestToken); } else if (service.getVersion() == "2.0") { OAuth20Service oAuth20Service = (OAuth20Service) service; authorizeUrl = oAuth20Service.getAuthorizationUrl(null); } } catch (Exception e) { this.e = e; } }
@Override public void signRequest(String accessToken, OAuthRequest request) { super.signRequest(accessToken, request); request.addHeader("X-Client-ID", getApiKey()); } }
if (service.getVersion() == "1.0") { OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken; OAuth10aService oAuth10aService = (OAuth10aService) service; accessToken = oAuth10aService.getAccessToken(oAuth1RequestToken, oauth_verifier); "and access token cannot be retrieved"); } else if (service.getVersion() == "2.0") { if (authorizedUri.getQuery().contains(OAuthConstants.CODE)) { String code = authorizedUri.getQueryParameter(OAuthConstants.CODE); OAuth20Service oAuth20Service = (OAuth20Service) service; accessToken = oAuth20Service.getAccessToken(code);
@Override protected OAuth2AccessToken doInBackground(Void... params) { try { final OAuth2AccessToken accessToken = (OAuth2AccessToken) oauth20Service.getAccessToken(authorizationCode); return accessToken; } catch (OAuthConnectionException ex) { Log.e(TAG, "OAuth connection exception: " + ex.getMessage()); ex.printStackTrace(); return null; } catch (IOException ex) { Log.e(TAG, "An exception occurred getRequestToken: " + ex.getMessage()); ex.printStackTrace(); return null; } }
public String linkFor(String idpId, String redirectPage) { AbstractOAuth2AuthenticationProvider idp = authenticationSvc.getOAuth2Provider(idpId); return idp.getService(createState(idp, toOption(redirectPage) ), getCallbackUrl()).getAuthorizationUrl(); }
@Override public Response execute(OAuthRequest request) throws InterruptedException, ExecutionException, IOException { OAuthRequest authRequest = addClientAuthentication(request); return super.execute(authRequest); }
@Override protected OAuth1AccessToken doInBackground(Void... params) { try { final OAuth1AccessToken accessToken = (OAuth1AccessToken) oauth10aService.getAccessToken(oauth1RequestToken, oauthVerifier); return accessToken; } catch (OAuthConnectionException ex) { Log.e(TAG, "OAuth connection exception: " + ex.getMessage()); ex.printStackTrace(); return null; } catch (IOException ex) { Log.e(TAG, "An exception occurred getRequestToken: " + ex.getMessage()); ex.printStackTrace(); return null; } }
/** * Get the auth URL, this is step two of authorization. * * @param oAuthRequestToken * the token from a {@link AuthInterface#getRequestToken} call. */ public String getAuthorizationUrl(OAuth1RequestToken oAuthRequestToken, Permission permission) { OAuth10aService service = new ServiceBuilder(apiKey) .apiSecret(sharedSecret) .build(FlickrApi.instance()); String authorizationUrl = service.getAuthorizationUrl(oAuthRequestToken); return String.format("%s&perms=%s", authorizationUrl, permission.toString()); }
/** * Get the OAuth request token - this is step one of authorization. * * @param callbackUrl * optional callback URL - required for web auth flow, will be set to "oob" if not specified. * @return the {@link OAuth1RequestToken}, store this for when the user returns from the Flickr website. */ public OAuth1RequestToken getRequestToken(String callbackUrl) { String callback = (callbackUrl != null) ? callbackUrl : OUT_OF_BOUND_AUTH_METHOD; OAuth10aService service = new ServiceBuilder(apiKey) .apiSecret(sharedSecret) .callback(callback) .build(FlickrApi.instance()); try { return service.getRequestToken(); } catch (IOException | InterruptedException | ExecutionException e) { throw new FlickrRuntimeException(e); } }
public void onPostExecute() { if (e != null) { handler.onFailure(e); } else { handler.onReceivedRequestToken(requestToken, authorizeUrl, service.getVersion()); } } });
@Override public void init(InitContext context) { OAuthService scribe = prepareScribe(context).build(); String url = scribe.getAuthorizationUrl(EMPTY_TOKEN); context.redirectTo(url); }
final OAuth20Service service = util.getService(); final OAuthRequest request = new OAuthRequest(Verb.POST, url, service); request.addHeader("Content-Type", "application/json;charset=UTF-8"); request.addPayload(MAPPER.writeValueAsString(requestModel)); // or this if you have a json string // request.addPayload(json); service.signRequest(new OAuth2AccessToken(accessToken), request); final Response postResponse = request.send();
@Override protected void retrieveAccessToken(final WebContext context, final OAuthCredentials credentials) { OAuth20Credentials oAuth20Credentials = (OAuth20Credentials) credentials; // no request token saved in context and no token (OAuth v2.0) final String code = oAuth20Credentials.getCode(); logger.debug("code: {}", code); final OAuth2AccessToken accessToken; try { accessToken = this.configuration.buildService(context, client, null).getAccessToken(code); } catch (final IOException | InterruptedException | ExecutionException e) { throw new HttpCommunicationException("Error getting token:" + e.getMessage()); } logger.debug("accessToken: {}", accessToken); oAuth20Credentials.setAccessToken(accessToken); } }
@Override protected void signRequest(final OAuth10aService service, final OAuth1AccessToken token, final OAuthRequest request) { service.signRequest(token, request); if (this.configuration.isTokenAsHeader()) { request.addHeader("Authorization", "Bearer " + token.getToken()); } } }
@Override public <R> Future<R> execute(OAuthRequest request, OAuthAsyncRequestCallback<R> callback, OAuthRequest.ResponseConverter<R> converter) { OAuthRequest authRequest = addClientAuthentication(request); return super.execute(authRequest, callback, converter); }
public void onPostExecute() { if (e != null) { handler.onFailure(e); } else { setAccessToken(accessToken); handler.onReceivedAccessToken(accessToken, service.getVersion()); } } });
private SocialUser getAccount(OAuth20Service service, OAuth2AccessToken accessToken) { try { OAuthRequest request = new OAuthRequest(Verb.GET, getAccountUrl, service); service.signRequest(accessToken, request); Response response = request.send(); return toAccount(response.getBody()); } catch (Exception e) { return null; } }
@Override protected void signRequest(final OAuth20Service service, final OAuth2AccessToken accessToken, final OAuthRequest request) { service.signRequest(accessToken, request); if (this.configuration.isTokenAsHeader()) { request.addHeader(HttpConstants.AUTHORIZATION_HEADER, HttpConstants.BEARER_HEADER_PREFIX + accessToken.getAccessToken()); } if (Verb.POST.equals(request.getVerb())) { request.addParameter(OAuthConfiguration.OAUTH_TOKEN, accessToken.getAccessToken()); } } }