com.github.scribejava.core.oauth.OAuth10aService Java Examples
The following examples show how to use
com.github.scribejava.core.oauth.OAuth10aService.
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: Oauth10aService.java From jweb-cms with GNU Affero General Public License v3.0 | 6 votes |
private OAuth10aService service(Provider provider) { OauthStrategy strategy = strategy(provider); String secretState = "secret" + new Random().nextInt(999_999); OAuth10aService service = services.get(provider); if (service == null) { ServiceBuilder serviceBuilder = new ServiceBuilder(strategy.clientId) .apiSecret(strategy.clientSecret) .state(secretState) .callback(strategy.callback); if (!Strings.isNullOrEmpty(provider.scope)) { serviceBuilder.scope(provider.scope); } service = serviceBuilder .build(instance(provider)); services.put(provider, service); } return service; }
Example #2
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 #3
Source File: OAuthManagerProviders.java From react-native-oauth with MIT License | 6 votes |
private static OAuth10aService twitterService( final HashMap cfg, @Nullable final ReadableMap opts, final String callbackUrl) { String consumerKey = (String) cfg.get("consumer_key"); String consumerSecret = (String) cfg.get("consumer_secret"); ServiceBuilder builder = new ServiceBuilder() .apiKey(consumerKey) .apiSecret(consumerSecret) .debug(); String scopes = (String) cfg.get("scopes"); if (scopes != null) { // String scopeStr = OAuthManagerProviders.getScopeString(scopes, "+"); // Log.d(TAG, "scopeStr: " + scopeStr); // builder.scope(scopeStr); } if (callbackUrl != null) { builder.callback(callbackUrl); } return builder.build(TwitterApi.instance()); }
Example #4
Source File: OAuthManagerFragmentController.java From react-native-oauth with MIT License | 6 votes |
public OAuthManagerFragmentController( final ReactContext mReactContext, android.app.FragmentManager fragmentManager, final String providerName, OAuth10aService oauthService, final String callbackUrl ) { this.uiHandler = new Handler(Looper.getMainLooper()); this.fragmentManager = fragmentManager; this.context = mReactContext; this.providerName = providerName; this.authVersion = "1.0"; this.oauth10aService = oauthService; this.callbackUrl = callbackUrl; }
Example #5
Source File: JamAuthConfig.java From jam-collaboration-sample with Apache License 2.0 | 6 votes |
public String getSingleUseToken() { OAuth10aService service = JamAuthConfig.instance().getOAuth10aService(); final OAuthRequest request = new OAuthRequest(Verb.POST, JamAuthConfig.instance().getServerUrl() + "/v1/single_use_tokens", service); service.signRequest(JamAuthConfig.instance().getOAuth10aAccessToken(), request); final Response response = request.send(); String body = response.getBody(); Matcher matcher = SINGLE_USE_TOKEN_PATTERN.matcher(body); if (matcher.find()) { return matcher.group(0); } return null; }
Example #6
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 #7
Source File: Oauth10aService.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
public String redirectUri(Provider provider) { OAuth10aService service = service(provider); try { OAuth1RequestToken requestToken = service.getRequestToken(); sessionInfo.put(REQUEST_TOKEN_PREFIX + provider.name(), JSON.toJSON(requestToken)); return service.getAuthorizationUrl(requestToken); } catch (InterruptedException | ExecutionException | IOException e) { throw new NotAuthorizedException("login failure", e); } }
Example #8
Source File: OAuthManagerProviders.java From react-native-oauth with MIT License | 5 votes |
static public OAuth10aService getApiFor10aProvider( final String providerName, final HashMap params, @Nullable final ReadableMap opts, final String callbackUrl ) { if (providerName.equalsIgnoreCase("twitter")) { return OAuthManagerProviders.twitterService(params, opts, callbackUrl); } else { return null; } }
Example #9
Source File: MainActivity.java From jam-collaboration-sample with Apache License 2.0 | 5 votes |
public void beginOAuthLogin() { final OAuth10aService service = JamAuthConfig.instance().getOAuth10aService(); AsyncTask network = new AsyncTask() { @Override protected Object doInBackground(Object[] params) { return service.getRequestToken(); } @Override protected void onPostExecute(Object object) { super.onPostExecute(object); if (object != null) { final OAuth1RequestToken requestToken = (OAuth1RequestToken) object; String authUrl = service.getAuthorizationUrl(requestToken); JamOAuthDialog dialog = new JamOAuthDialog(MainActivity.this, authUrl); dialog.oauthListener = new JamOAuthDialog.ConfirmedOAuthAccessListener() { @Override public void onFinishOAuthAccess(String oauthToken, String oauthVerifier) { processOAuthVerifier(requestToken, oauthVerifier); } }; dialog.show(); } } }; network.execute(); }
Example #10
Source File: TwitterController.java From tutorials with MIT License | 5 votes |
@GetMapping(value = "/authorization") public RedirectView authorization(HttpServletRequest servletReq) throws InterruptedException, ExecutionException, IOException { OAuth10aService twitterService = createService(); OAuth1RequestToken requestToken = twitterService.getRequestToken(); String authorizationUrl = twitterService.getAuthorizationUrl(requestToken); servletReq.getSession().setAttribute("requestToken", requestToken); RedirectView redirectView = new RedirectView(); redirectView.setUrl(authorizationUrl); return redirectView; }
Example #11
Source File: TwitterController.java From tutorials with MIT License | 5 votes |
@GetMapping(value = "/callback", produces = "text/plain") @ResponseBody public String callback(HttpServletRequest servletReq, @RequestParam("oauth_verifier") String oauthV) throws InterruptedException, ExecutionException, IOException { OAuth10aService twitterService = createService(); OAuth1RequestToken requestToken = (OAuth1RequestToken) servletReq.getSession().getAttribute("requestToken"); OAuth1AccessToken accessToken = twitterService.getAccessToken(requestToken, oauthV); OAuthRequest request = new OAuthRequest(Verb.GET, "https://api.twitter.com/1.1/account/verify_credentials.json"); twitterService.signRequest(accessToken, request); Response response = twitterService.execute(request); return response.getBody(); }
Example #12
Source File: JamAuthConfig.java From jam-collaboration-sample with Apache License 2.0 | 4 votes |
public OAuth10aService getOAuth10aService() { return oauthService; }
Example #13
Source File: TwitterController.java From tutorials with MIT License | 4 votes |
private OAuth10aService createService() { return new ServiceBuilder("PSRszoHhRDVhyo2RIkThEbWko") .apiSecret("prpJbz03DcGRN46sb4ucdSYtVxG8unUKhcnu3an5ItXbEOuenL") .callback("http://localhost:8080/spring-mvc-simple/twitter/callback") .build(TwitterApi.instance()); }
Example #14
Source File: TwitterService.java From tutorials with MIT License | 4 votes |
public OAuth10aService getService(){ return service; }
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")); } } }