com.github.scribejava.core.model.OAuth1AccessToken Java Examples
The following examples show how to use
com.github.scribejava.core.model.OAuth1AccessToken.
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: OAuthManagerProviders.java From react-native-oauth with MIT License | 6 votes |
static public OAuthRequest getRequestForProvider( final String providerName, final Verb httpVerb, final OAuth1AccessToken oa1token, final URL url, final HashMap<String,Object> cfg, @Nullable final ReadableMap params ) { final OAuth10aService service = OAuthManagerProviders.getApiFor10aProvider(providerName, cfg, null, null); String token = oa1token.getToken(); OAuthConfig config = service.getConfig(); OAuthRequest request = new OAuthRequest(httpVerb, url.toString(), config); request = OAuthManagerProviders.addParametersToRequest(request, token, params); // Nothing special for Twitter return request; }
Example #2
Source File: MainActivity.java From jam-collaboration-sample with Apache License 2.0 | 6 votes |
private void processOAuthVerifier(final OAuth1RequestToken requestToken, final String oauthVerifier) { final OAuth10aService service = JamAuthConfig.instance().getOAuth10aService(); AsyncTask network = new AsyncTask() { @Override protected Object doInBackground(Object[] params) { final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); JamAuthConfig.instance().storeCredentials(accessToken); return true; } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); goToMainApp(); } }; network.execute(); }
Example #3
Source File: TwitterCallbackPath.java From PYX-Reloaded with Apache License 2.0 | 5 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.startBlocking(); if (exchange.isInIoThread()) { exchange.dispatch(this); return; } try { String token = Utils.extractParam(exchange, "oauth_token"); String verifier = Utils.extractParam(exchange, "oauth_verifier"); if (token == null || verifier == null) throw new IllegalArgumentException("Missing token or verifier!"); Cookie tokensCookie = exchange.getRequestCookies().get("PYX-Twitter-Token"); if (tokensCookie == null) throw new IllegalArgumentException("Missing 'PYX-Twitter-Token' cookie!"); List<NameValuePair> tokens = URLEncodedUtils.parse(tokensCookie.getValue(), Charset.forName("UTF-8")); if (!Objects.equals(token, Utils.get(tokens, "oauth_token"))) throw new IllegalStateException("Missing token in cookie or tokens don't match!"); String secret = Utils.get(tokens, "oauth_token_secret"); if (secret == null) throw new IllegalArgumentException("Missing token secret in cookie!"); OAuth1AccessToken accessToken = helper.accessToken(new OAuth1RequestToken(token, secret), verifier); CookieImpl cookie = new CookieImpl("PYX-Twitter-Token", accessToken.getRawResponse()); cookie.setMaxAge(COOKIE_MAX_AGE); exchange.setResponseCookie(cookie); exchange.getResponseHeaders().add(Headers.LOCATION, REDIRECT_LOCATION); exchange.setStatusCode(StatusCodes.TEMPORARY_REDIRECT); } catch (Throwable ex) { logger.error("Failed processing the request: " + exchange, ex); throw ex; } }
Example #4
Source File: OAuthManagerStore.java From react-native-oauth with MIT License | 5 votes |
public void store(String providerName, final OAuth1AccessToken accessToken) { if (accessToken == null) { throw new IllegalArgumentException("Token is null"); } if (providerName.equals("") || providerName == null) { throw new IllegalArgumentException("Provider is null"); } editor.putString(providerName, new Gson().toJson(accessToken)); }
Example #5
Source File: OAuthManagerFragmentController.java From react-native-oauth with MIT License | 5 votes |
public void loaded10aAccessToken(final OAuth1AccessToken accessToken) { Log.d(TAG, "Loaded access token in OAuthManagerFragmentController"); Log.d(TAG, "AccessToken: " + accessToken + " (raw: " + accessToken.getRawResponse() + ")"); mWebView = null; this.dismissDialog(); mListener.onOAuth1AccessToken(accessToken); }
Example #6
Source File: OAuthManagerFragmentController.java From react-native-oauth with MIT License | 5 votes |
@Override protected void onPostExecute(final OAuth1AccessToken accessToken) { runOnMainThread(new Runnable() { @Override public void run() { if (accessToken == null) { mCtrl.onError(-1, "No accessToken found", ""); return; } mCtrl.loaded10aAccessToken(accessToken); } }); }
Example #7
Source File: JamAuthConfig.java From jam-collaboration-sample with Apache License 2.0 | 5 votes |
public void storeCredentials(OAuth1AccessToken accessToken) { this.oauthToken = accessToken; // TODO: store access token and secret in AccountManager or more securely // Using SharedPreferences for demonstration Context appContext = JamSDKDemoApp.getAppContext(); SharedPreferences.Editor prefEditor = appContext.getSharedPreferences(PREF_KEY, 0).edit(); prefEditor.putString(PREF_ACCESS_TOKEN, accessToken.getToken()); prefEditor.putString(PREF_ACCESS_SECRET, accessToken.getTokenSecret()); prefEditor.commit(); }
Example #8
Source File: OAuthBaseClient.java From android-oauth-handler with MIT License | 5 votes |
public void instantiateClient(String consumerKey, String consumerSecret, Token token) { if (token instanceof OAuth1AccessToken) { client = OAuthAsyncHttpClient.create(consumerKey, consumerSecret, (OAuth1AccessToken)(token)); } else if (token instanceof OAuth2AccessToken){ client = OAuthAsyncHttpClient.create((OAuth2AccessToken) token); } else { throw new IllegalStateException("unrecognized token type" + token); } }
Example #9
Source File: OAuthBaseClient.java From android-oauth-handler with MIT License | 5 votes |
public Token checkAccessToken() { int oAuthVersion = prefs.getInt(OAuthConstants.VERSION, 0); if (oAuthVersion == 1 && prefs.contains(OAuthConstants.TOKEN) && prefs.contains(OAuthConstants.TOKEN_SECRET)) { return new OAuth1AccessToken(prefs.getString(OAuthConstants.TOKEN, ""), prefs.getString(OAuthConstants.TOKEN_SECRET, "")); } else if (oAuthVersion == 2 && prefs.contains(OAuthConstants.TOKEN)) { return new OAuth2AccessToken(prefs.getString(OAuthConstants.TOKEN, "")); } return null; }
Example #10
Source File: OAuthAsyncHttpClient.java From android-oauth-handler with MIT License | 5 votes |
public static OAuthAsyncHttpClient create(String consumerKey, String consumerSecret, OAuth1AccessToken token) { OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(consumerKey, consumerSecret); HttpLoggingInterceptor logging = createLogger(); consumer.setTokenWithSecret(token.getToken(), token.getTokenSecret()); OkHttpClient httpClient = new OkHttpClient.Builder() .addInterceptor(logging) .addNetworkInterceptor(new StethoInterceptor()) .addInterceptor(new SigningInterceptor(consumer)).build(); OAuthAsyncHttpClient asyncHttpClient = new OAuthAsyncHttpClient(httpClient); return asyncHttpClient; }
Example #11
Source File: OAuthManagerModule.java From react-native-oauth with MIT License | 4 votes |
private OAuthRequest oauthRequestWithParams( final String providerName, final HashMap<String,Object> cfg, final String authVersion, final Verb httpVerb, final URL url, @Nullable final ReadableMap params ) throws Exception { OAuthRequest request; // OAuthConfig config; if (authVersion.equals("1.0")) { // final OAuth10aService service = // OAuthManagerProviders.getApiFor10aProvider(providerName, cfg, null, null); OAuth1AccessToken oa1token = _credentialsStore.get(providerName, OAuth1AccessToken.class); request = OAuthManagerProviders.getRequestForProvider( providerName, httpVerb, oa1token, url, cfg, params); // config = service.getConfig(); // request = new OAuthRequest(httpVerb, url.toString(), config); } else if (authVersion.equals("2.0")) { // final OAuth20Service service = // OAuthManagerProviders.getApiFor20Provider(providerName, cfg, null, null); // oa2token = _credentialsStore.get(providerName, OAuth2AccessToken.class); OAuth2AccessToken oa2token = _credentialsStore.get(providerName, OAuth2AccessToken.class); request = OAuthManagerProviders.getRequestForProvider( providerName, httpVerb, oa2token, url, cfg, params); // config = service.getConfig(); // request = new OAuthRequest(httpVerb, url.toString(), config); } else { Log.e(TAG, "Error in making request method"); throw new Exception("Provider not handled yet"); } return request; }
Example #12
Source File: OAuthManagerDialogFragment.java From react-native-oauth with MIT License | 4 votes |
public void setComplete(final OAuth1AccessToken accessToken) { Log.d(TAG, "Completed: " + accessToken); }
Example #13
Source File: JamAuthConfig.java From jam-collaboration-sample with Apache License 2.0 | 4 votes |
public OAuth1AccessToken getOAuth10aAccessToken() { return oauthToken; }
Example #14
Source File: OAuthBaseClient.java From android-oauth-handler with MIT License | 4 votes |
public OAuthBaseClient(Context c, final BaseApi apiInstance, String consumerUrl, final String consumerKey, final String consumerSecret, @Nullable String scope, String callbackUrl) { this.baseUrl = consumerUrl; this.callbackUrl = callbackUrl; tokenClient = new OAuthTokenClient(apiInstance, consumerKey, consumerSecret, callbackUrl, scope, new OAuthTokenClient.OAuthTokenHandler() { // Store request token and launch the authorization URL in the browser @Override public void onReceivedRequestToken(Token requestToken, String authorizeUrl, String oAuthVersion) { if (requestToken != null) { if (oAuthVersion == OAUTH1_VERSION) { // store for OAuth1.0a OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken; editor.putString(OAUTH1_REQUEST_TOKEN, oAuth1RequestToken.getToken()); editor.putString(OAUTH1_REQUEST_TOKEN_SECRET, oAuth1RequestToken.getTokenSecret()); editor.putInt(OAuthConstants.VERSION, 1); editor.commit(); } } // Launch the authorization URL in the browser Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authorizeUrl)); if (requestIntentFlags != -1) { intent.setFlags(requestIntentFlags); } OAuthBaseClient.this.context.startActivity(intent); } // Store the access token in preferences, set the token in the tokenClient and fire the success callback @Override public void onReceivedAccessToken(Token accessToken, String oAuthVersion) { if (oAuthVersion == OAUTH1_VERSION) { OAuth1AccessToken oAuth1AccessToken = (OAuth1AccessToken) accessToken; tokenClient.setAccessToken(accessToken); instantiateClient(consumerKey, consumerSecret, oAuth1AccessToken); editor.putString(OAuthConstants.TOKEN, oAuth1AccessToken.getToken()); editor.putString(OAuthConstants.TOKEN_SECRET, oAuth1AccessToken.getTokenSecret()); editor.putInt(OAuthConstants.VERSION, 1); editor.commit(); } else if (oAuthVersion == OAUTH2_VERSION) { OAuth2AccessToken oAuth2AccessToken = (OAuth2AccessToken) accessToken; instantiateClient(consumerKey, consumerSecret, oAuth2AccessToken); tokenClient.setAccessToken(accessToken); editor.putString(OAuthConstants.TOKEN, oAuth2AccessToken.getAccessToken()); editor.putString(OAuthConstants.SCOPE, oAuth2AccessToken.getScope()); editor.putString(OAuthConstants.REFRESH_TOKEN, oAuth2AccessToken.getRefreshToken()); editor.putInt(OAuthConstants.VERSION, 2); editor.commit(); } accessHandler.onLoginSuccess(); } @Override public void onFailure(Exception e) { accessHandler.onLoginFailure(e); } }); this.context = c; // Store preferences namespaced by the class and consumer key used this.prefs = this.context.getSharedPreferences("OAuth_" + apiInstance.getClass().getSimpleName() + "_" + consumerKey, 0); this.editor = this.prefs.edit(); // Set access token in the tokenClient if already stored in preferences Token accessToken = this.checkAccessToken(); if (accessToken != null) { tokenClient.setAccessToken(accessToken); instantiateClient(consumerKey, consumerSecret, accessToken); } }
Example #15
Source File: OAuthTokenClient.java From android-oauth-handler with MIT License | 4 votes |
public void fetchAccessToken(final Token requestToken, final Uri uri) { Uri authorizedUri = uri; if (service.getVersion() == "1.0") { // Use verifier token to fetch access token if (authorizedUri.getQuery().contains(OAuthConstants.VERIFIER)) { String oauth_verifier = authorizedUri.getQueryParameter(OAuthConstants.VERIFIER); OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken; OAuth10aService oAuth10aService = (OAuth10aService) service; oAuth10aService.getAccessTokenAsync(oAuth1RequestToken, oauth_verifier, new OAuthAsyncRequestCallback<OAuth1AccessToken>() { @Override public void onCompleted(OAuth1AccessToken oAuth1AccessToken) { setAccessToken(oAuth1AccessToken); handler.onReceivedAccessToken(oAuth1AccessToken, service.getVersion()); } @Override public void onThrowable(Throwable e) { handler.onFailure(new OAuthException(e.getMessage())); } }); } else { // verifier was null throw new OAuthException("No verifier code was returned with uri '" + uri + "' " + "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; oAuth20Service.getAccessToken(code, new OAuthAsyncRequestCallback<OAuth2AccessToken>() { @Override public void onCompleted(OAuth2AccessToken accessToken) { setAccessToken(accessToken); handler.onReceivedAccessToken(accessToken, service.getVersion()); } @Override public void onThrowable(Throwable t) { } }); } else { // verifier was null handler.onFailure(new OAuthException("No code was returned with uri '" + uri + "' " + "and access token cannot be retrieved")); } } }
Example #16
Source File: OAuthManagerOnAccessTokenListener.java From react-native-oauth with MIT License | votes |
void onOAuth1AccessToken(final OAuth1AccessToken accessToken);