org.scribe.oauth.OAuthService Java Examples
The following examples show how to use
org.scribe.oauth.OAuthService.
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: ResourceClient.java From jerseyoauth2 with MIT License | 7 votes |
public SampleEntity retrieveEntitySample1(Token accessToken) throws ClientException { OAuthService service = getOAuthService(scopes, null); OAuthRequest request = new OAuthRequest(Verb.GET, "http://localhost:9998/testsuite/rest/sample/1"); service.signRequest(accessToken, request); Response response = request.send(); if (response.getCode()!=200) throwClientException(response); ObjectMapper mapper = new ObjectMapper(); try { SampleEntity entity = mapper.readValue(response.getBody(), SampleEntity.class); return entity; } catch (IOException e) { throw new ClientException(response.getBody()); } }
Example #2
Source File: BasicRESTClient.java From secure-data-service with Apache License 2.0 | 6 votes |
@Override public Response connect(final String authorizationCode) throws OAuthException, MalformedURLException, URISyntaxException { OAuthService service = new ServiceBuilder().provider(SliApi.class).apiKey(config.getApiKey()) .apiSecret(config.getApiSecret()).callback(config.getCallback()).build(); Verifier verifier = new Verifier(authorizationCode); SliApi.TokenResponse r = ((SliApi.SLIOauth20ServiceImpl) service).getAccessToken( new Token(config.getApiSecret(), authorizationCode), verifier, null); if (r != null && r.getToken() != null) { accessToken = r.getToken(); sessionToken = accessToken.getToken(); } ResponseBuilder builder = Response.status(r.getOauthResponse().getCode()); for (Map.Entry<String, String> entry : r.getOauthResponse().getHeaders().entrySet()) { if (entry.getKey() == null) { builder.header("Status", entry.getValue()); } else { builder.header(entry.getKey(), entry.getValue()); } } builder.entity(r.getOauthResponse().getBody()); return builder.build(); }
Example #3
Source File: EvernoteOAuthActivity.java From EverMemo-EverNote with MIT License | 5 votes |
@Override protected EvernoteAuthToken doInBackground(Uri... uris) { EvernoteAuthToken authToken = null; if (uris == null || uris.length == 0) { return null; } Uri uri = uris[0]; if (!TextUtils.isEmpty(mRequestToken)) { OAuthService service = createService(); String verifierString = uri.getQueryParameter("oauth_verifier"); if (TextUtils.isEmpty(verifierString)) { Log.i(LOGTAG, "User did not authorize access"); } else { Verifier verifier = new Verifier(verifierString); Log.i(LOGTAG, "Retrieving OAuth access token..."); try { Token reqToken = new Token(mRequestToken, mRequestTokenSecret); authToken = new EvernoteAuthToken(service.getAccessToken(reqToken, verifier)); } catch (Exception ex) { Log.e(LOGTAG, "Failed to obtain OAuth access token", ex); } } } else { Log.d(LOGTAG, "Unable to retrieve OAuth access token, no request token"); } return authToken; }
Example #4
Source File: EvernoteOAuthActivity.java From EverMemo-EverNote with MIT License | 5 votes |
@Override protected String doInBackground(Void... params) { String url = null; try { EvernoteSession session = EvernoteSession.getOpenSession(); if (session != null) { //Network request BootstrapManager.BootstrapInfoWrapper infoWrapper = session.getBootstrapSession().getBootstrapInfo(); if (infoWrapper != null){ BootstrapInfo info = infoWrapper.getBootstrapInfo(); if(info != null) { mBootstrapProfiles = (ArrayList<BootstrapProfile>) info.getProfiles(); if (mBootstrapProfiles != null && mBootstrapProfiles.size() > 0 && mSelectedBootstrapProfilePos < mBootstrapProfiles.size()){ mSelectedBootstrapProfile = mBootstrapProfiles.get(mSelectedBootstrapProfilePos); } } } } if(mSelectedBootstrapProfile == null || TextUtils.isEmpty(mSelectedBootstrapProfile.getSettings().getServiceHost())) { Log.d(LOGTAG, "Bootstrap did not return a valid host"); return null; } OAuthService service = createService(); Log.i(LOGTAG, "Retrieving OAuth request token..."); Token reqToken = service.getRequestToken(); mRequestToken = reqToken.getToken(); mRequestTokenSecret = reqToken.getSecret(); Log.i(LOGTAG, "Redirecting user for authorization..."); url = service.getAuthorizationUrl(reqToken); } catch(BootstrapManager.ClientUnsupportedException cue) { return null; } catch (Exception ex) { Log.e(LOGTAG, "Failed to obtain OAuth request token", ex); } return url; }
Example #5
Source File: EvernoteOAuthActivity.java From EverMemo-EverNote with MIT License | 5 votes |
/** * Create a Scribe OAuthService object that can be used to * perform OAuth authentication with the appropriate Evernote * service. */ @SuppressWarnings("unchecked") private OAuthService createService() { OAuthService builder = null; @SuppressWarnings("rawtypes") Class apiClass = null; String host = mSelectedBootstrapProfile.getSettings().getServiceHost(); if (host != null && !host.startsWith("http")) { host = "https://" + host; } if (host.equals(EvernoteSession.HOST_SANDBOX)) { apiClass = EvernoteApi.Sandbox.class; } else if (host.equals(EvernoteSession.HOST_PRODUCTION)) { apiClass = EvernoteApi.class; } else if (host.equals(EvernoteSession.HOST_CHINA)) { apiClass = YinxiangApi.class; } else { throw new IllegalArgumentException("Unsupported Evernote host: " + host); } builder = new ServiceBuilder() .provider(apiClass) .apiKey(mConsumerKey) .apiSecret(mConsumerSecret) .callback(getCallbackScheme() + "://callback") .build(); return builder; }
Example #6
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 5 votes |
public String sendTestRequestSample2(Token accessToken) throws ClientException { OAuthService service = getOAuthService(null, null); OAuthRequest request = new OAuthRequest(Verb.GET, "http://localhost:9998/testsuite/rest/sample2/1"); service.signRequest(accessToken, request); Response response = request.send(); if (response.getCode()!=200) throwClientException(response); return response.getBody(); }
Example #7
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 5 votes |
public String sendTestRequestSample1(Token accessToken) throws ClientException { OAuthService service = getOAuthService(scopes, null); OAuthRequest request = new OAuthRequest(Verb.GET, "http://localhost:9998/testsuite/rest/sample/1"); service.signRequest(accessToken, request); Response response = request.send(); if (response.getCode()!=200) throwClientException(response); return response.getBody(); }
Example #8
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 5 votes |
protected OAuthService getOAuthService(GrantType _grantType, String scope, String state) { ServiceBuilder serviceBuilder = new ServiceBuilder() .provider(new TestsuiteAPI(_grantType.getTechnicalCode(), state, responseType.getTechnicalCode())) .apiKey(clientId) .apiSecret(clientSecret==null?"DUMMYDUMMYDUMMY":clientSecret) .callback("http://localhost:9998/testsuite"); if (scope!=null) serviceBuilder = serviceBuilder.scope(scope); OAuthService service = serviceBuilder.build(); return service; }
Example #9
Source File: EvernoteOAuthActivity.java From EverMemo with MIT License | 5 votes |
@Override protected EvernoteAuthToken doInBackground(Uri... uris) { EvernoteAuthToken authToken = null; if (uris == null || uris.length == 0) { return null; } Uri uri = uris[0]; if (!TextUtils.isEmpty(mRequestToken)) { OAuthService service = createService(); String verifierString = uri.getQueryParameter("oauth_verifier"); if (TextUtils.isEmpty(verifierString)) { Log.i(LOGTAG, "User did not authorize access"); } else { Verifier verifier = new Verifier(verifierString); Log.i(LOGTAG, "Retrieving OAuth access token..."); try { Token reqToken = new Token(mRequestToken, mRequestTokenSecret); authToken = new EvernoteAuthToken( service.getAccessToken(reqToken, verifier)); } catch (Exception ex) { Log.e(LOGTAG, "Failed to obtain OAuth access token", ex); } } } else { Log.d(LOGTAG, "Unable to retrieve OAuth access token, no request token"); } return authToken; }
Example #10
Source File: EvernoteOAuthActivity.java From EverMemo with MIT License | 5 votes |
@Override protected String doInBackground(Void... params) { String url = null; try { EvernoteSession session = EvernoteSession.getOpenSession(); if (session != null) { // Network request BootstrapManager.BootstrapInfoWrapper infoWrapper = session .getBootstrapSession().getBootstrapInfo(); if (infoWrapper != null) { BootstrapInfo info = infoWrapper.getBootstrapInfo(); if (info != null) { mBootstrapProfiles = (ArrayList<BootstrapProfile>) info .getProfiles(); if (mBootstrapProfiles != null && mBootstrapProfiles.size() > 0 && mSelectedBootstrapProfilePos < mBootstrapProfiles .size()) { mSelectedBootstrapProfile = mBootstrapProfiles .get(mSelectedBootstrapProfilePos); } } } } if (mSelectedBootstrapProfile == null || TextUtils.isEmpty(mSelectedBootstrapProfile .getSettings().getServiceHost())) { Log.d(LOGTAG, "Bootstrap did not return a valid host"); return null; } OAuthService service = createService(); Log.i(LOGTAG, "Retrieving OAuth request token..."); Token reqToken = service.getRequestToken(); mRequestToken = reqToken.getToken(); mRequestTokenSecret = reqToken.getSecret(); Log.i(LOGTAG, "Redirecting user for authorization..."); url = service.getAuthorizationUrl(reqToken); } catch (BootstrapManager.ClientUnsupportedException cue) { return null; } catch (Exception ex) { Log.e(LOGTAG, "Failed to obtain OAuth request token", ex); } return url; }
Example #11
Source File: EvernoteOAuthActivity.java From EverMemo with MIT License | 5 votes |
/** * Create a Scribe OAuthService object that can be used to perform OAuth * authentication with the appropriate Evernote service. */ @SuppressWarnings("unchecked") private OAuthService createService() { OAuthService builder = null; @SuppressWarnings("rawtypes") Class apiClass = null; String host = mSelectedBootstrapProfile.getSettings().getServiceHost(); if (host != null && !host.startsWith("http")) { host = "https://" + host; } if (host.equals(EvernoteSession.HOST_SANDBOX)) { apiClass = EvernoteApi.Sandbox.class; } else if (host.equals(EvernoteSession.HOST_PRODUCTION)) { apiClass = EvernoteApi.class; } else if (host.equals(EvernoteSession.HOST_CHINA)) { apiClass = YinxiangApi.class; } else { throw new IllegalArgumentException("Unsupported Evernote host: " + host); } builder = new ServiceBuilder().provider(apiClass).apiKey(mConsumerKey) .apiSecret(mConsumerSecret) .callback(getCallbackScheme() + "://callback").build(); return builder; }
Example #12
Source File: SLIAuthenticationEntryPoint.java From secure-data-service with Apache License 2.0 | 5 votes |
private void verifyingAuthentication(HttpServletRequest request, HttpServletResponse response, HttpSession session, OAuthService service) throws IOException { LOG.info(LOG_MESSAGE_AUTH_VERIFYING, new Object[] { request.getRemoteAddr() }); Verifier verifier = new Verifier(request.getParameter(OAUTH_CODE)); Token accessToken = service.getAccessToken(null, verifier); session.setAttribute(OAUTH_TOKEN, accessToken.getToken()); Object entryUrl = session.getAttribute(ENTRY_URL); if (entryUrl != null) { response.sendRedirect(session.getAttribute(ENTRY_URL).toString()); } else { response.sendRedirect(request.getRequestURI()); } }
Example #13
Source File: SLIAuthenticationEntryPoint.java From secure-data-service with Apache License 2.0 | 5 votes |
private void initiatingAuthentication(HttpServletRequest request, HttpServletResponse response, HttpSession session, OAuthService service) throws IOException { LOG.info(LOG_MESSAGE_AUTH_INITIATING, new Object[] { request.getRemoteAddr() }); session.setAttribute(ENTRY_URL, request.getRequestURL()); // The request token doesn't matter for OAuth 2.0 which is why it's null String authUrl = service.getAuthorizationUrl(null); response.sendRedirect(authUrl); }
Example #14
Source File: DataUploadServiceTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void onStartCommand_shouldRemoveData() throws Exception { Token token = new Token("stuff", "fun"); OAuthService mockService = mock(OAuthService.class); ((MapzenApplication) Robolectric.application).setOsmOauthService(mockService); String readyGroupId = "ready"; String notReadyGroupId = "not-ready"; fillLocationsTable(readyGroupId, "ready", 10, true); fillLocationsTable(notReadyGroupId, "not-ready", 10, false); app.setAccessToken(token); service.onStartCommand(null, 0, 0); assertGroups(readyGroupId, notReadyGroupId); assertRoutes("ready", "not-ready"); assertLocations("ready", "not-ready"); }
Example #15
Source File: DataUploadServiceTest.java From open with GNU General Public License v3.0 | 5 votes |
@Ignore @Test public void onStartCommand_shouldMarkUploaded() throws Exception { Token token = new Token("stuff", "fun"); OAuthService mockService = mock(OAuthService.class); ((MapzenApplication) Robolectric.application).setOsmOauthService(mockService); String expectedGroupId = "route-1"; makeGroup(expectedGroupId, 1); app.setAccessToken(token); service.onStartCommand(null, 0, 0); Cursor cursor = db.query(TABLE_GROUPS, new String[] { COLUMN_UPLOADED }, COLUMN_TABLE_ID + " = ? AND " + COLUMN_UPLOADED + " = 1", new String[] { expectedGroupId }, null, null, null); assertThat(cursor).hasCount(1); }
Example #16
Source File: LoginWindow.java From jpa-invoicer with The Unlicense | 5 votes |
private OAuthService createService() { ServiceBuilder sb = new ServiceBuilder(); sb.provider(Google2Api.class); sb.apiKey(gpluskey); sb.apiSecret(gplussecret); sb.scope("email"); String callBackUrl = Page.getCurrent().getLocation().toString(); if(callBackUrl.contains("#")) { callBackUrl = callBackUrl.substring(0, callBackUrl.indexOf("#")); } sb.callback(callBackUrl); return sb.build(); }
Example #17
Source File: OAuthServiceCreator.java From mamute with Apache License 2.0 | 5 votes |
@Produces @Google public OAuthService getInstanceGoogle() { this.service = new ServiceBuilder() .provider(Google2Api.class) .apiKey(env.get(GOOGLE_CLIENT_ID)) .apiSecret(env.get(GOOGLE_CLIENT_SECRET)) .callback(env.get("host")+env.get(GOOGLE_REDIRECT_URI)) .scope("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email") .build(); return service; }
Example #18
Source File: OAuthServiceCreator.java From mamute with Apache License 2.0 | 5 votes |
@Produces @Facebook public OAuthService getInstanceFacebook() { this.service = new ServiceBuilder() .provider(FacebookApi.class) .apiKey(env.get(FACEBOOK_CLIENT_ID)) .apiSecret(env.get(FACEBOOK_APP_SECRET)) .callback(env.get("host")+env.get(FACEBOOK_REDIRECT_URI)) .build(); return service; }
Example #19
Source File: BitbucketApi.java From bitbucket-build-status-notifier-plugin with MIT License | 4 votes |
@Override public OAuthService createService(OAuthConfig config) { return new BitbucketApiService(this, config); }
Example #20
Source File: SLIAuthenticationEntryPoint.java From secure-data-service with Apache License 2.0 | 4 votes |
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { HttpSession session = request.getSession(); try { SliApi.setBaseUrl(apiUrl); // Setup OAuth service OAuthService service = new ServiceBuilder().provider(SliApi.class) .apiKey(propDecryptor.getDecryptedClientId()).apiSecret(propDecryptor.getDecryptedClientSecret()) .callback(callbackUrl).build(); // Check cookies for token, if found insert into session boolean cookieFound = checkCookiesForToken(request, session); Object token = session.getAttribute(OAUTH_TOKEN); if (token == null && request.getParameter(OAUTH_CODE) == null) { // Initiate authentication initiatingAuthentication(request, response, session, service); } else if (token == null && request.getParameter(OAUTH_CODE) != null) { // Verify authentication verifyingAuthentication(request, response, session, service); } else { // Complete authentication completeAuthentication(request, response, session, token, cookieFound); } } catch (OAuthException ex) { session.invalidate(); LOG.error(LOG_MESSAGE_AUTH_EXCEPTION, new Object[] { ex.getMessage() }); response.sendError(HttpServletResponse.SC_FORBIDDEN, ex.getMessage()); return; } /* catch (Exception ex) { session.invalidate(); LOG.error(LOG_MESSAGE_AUTH_EXCEPTION, new Object[] { ex.getMessage() }); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); return; }*/ }
Example #21
Source File: Google2Api.java From jpa-invoicer with The Unlicense | 4 votes |
@Override public OAuthService createService(OAuthConfig config) { return new GoogleOAuth2Service(this, config); }
Example #22
Source File: OAuth2ServiceWrapper.java From jerseyoauth2 with MIT License | 4 votes |
public OAuth2ServiceWrapper(OAuthService wrapped, DefaultApi20 api, OAuthConfig config) { this.wrapped = wrapped; this.api = api; this.config = config; }
Example #23
Source File: BaseOAuth2Api.java From jerseyoauth2 with MIT License | 4 votes |
@Override public OAuthService createService(OAuthConfig config) { return new OAuth2ServiceWrapper(super.createService(config), this, config); }
Example #24
Source File: FacebookAPI.java From mamute with Apache License 2.0 | 4 votes |
public FacebookAPI(OAuthService service, Token accessToken) { this.service = service; this.accessToken = accessToken; }
Example #25
Source File: GoogleAPI.java From mamute with Apache License 2.0 | 4 votes |
public GoogleAPI(Token accessToken, OAuthService service) { this.accessToken = accessToken; this.service = service; }
Example #26
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 4 votes |
public Token refreshToken(OAuth2Token token) { OAuthService service = getOAuthService(GrantType.REFRESH_TOKEN, scopes, null); return ((IOAuth2Service)service).refreshToken(token); }
Example #27
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 4 votes |
public Token getAccessToken(String code) { OAuthService service = getOAuthService(scopes, null); return service.getAccessToken(null, new Verifier(code)); }
Example #28
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 4 votes |
public String getAuthUrl(String state) { OAuthService service = getOAuthService(scopes, state); return service.getAuthorizationUrl(null); }
Example #29
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 4 votes |
protected OAuthService getOAuthService(String scope, String state) { return getOAuthService(grantType, scope, state); }
Example #30
Source File: HubicApi.java From swift-explorer with Apache License 2.0 | 4 votes |
@Override public OAuthService createService(OAuthConfig config) { return new HubicOAuth20ServiceImpl(this, config); }