org.scribe.builder.ServiceBuilder Java Examples

The following examples show how to use org.scribe.builder.ServiceBuilder. 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: HubicSwift.java    From swift-explorer with Apache License 2.0 6 votes vote down vote up
public static SwiftAccess getSwiftAccess ()
{
   	final HasAuthenticationSettings authSettings = Configuration.INSTANCE.getAuthenticationSettings() ;
	String apiKey = authSettings.getClientId() ;
	String apiSecret = authSettings.getClientSecret() ;

	HubicOAuth20ServiceImpl service = (HubicOAuth20ServiceImpl) new ServiceBuilder()
			.provider(HubicApi.class).apiKey(apiKey).apiSecret(apiSecret)
			//.scope("account.r,links.rw,usage.r,credentials.r").callback(HubicApi.CALLBACK_URL)
			.scope(scope).callback(HubicApi.CALLBACK_URL)
			.build();
	
	Verifier verif = service.obtainVerifier();
	
	if (verif == null)
		return null ;
	
	Token accessToken = service.getAccessToken(null, verif);
	return getSwiftAccess (service, accessToken) ;
}
 
Example #2
Source File: BasicRESTClient.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@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: SmugMugInterface.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
SmugMugInterface(AppCredentials appCredentials, TokenSecretAuthData authData, ObjectMapper mapper)
    throws IOException {
  this.oAuthService =
      new ServiceBuilder()
          .apiKey(appCredentials.getKey())
          .apiSecret(appCredentials.getSecret())
          .provider(SmugMugOauthApi.class)
          .build();
  this.accessToken = new Token(authData.getToken(), authData.getSecret());
  this.mapper = mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  this.user = getUserInformation().getUser();
}
 
Example #4
Source File: LoginWindow.java    From jpa-invoicer with The Unlicense 5 votes vote down vote up
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 #5
Source File: OAuthServiceCreator.java    From mamute with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: OAuthServiceCreator.java    From mamute with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: HubicSwift.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
public static SwiftAccess refreshAccessToken(Token expiredToken) 
{
	final HasAuthenticationSettings authSettings = Configuration.INSTANCE.getAuthenticationSettings();
	String apiKey = authSettings.getClientId();
	String apiSecret = authSettings.getClientSecret();

	HubicOAuth20ServiceImpl service = (HubicOAuth20ServiceImpl) new ServiceBuilder()
			.provider(HubicApi.class).apiKey(apiKey).apiSecret(apiSecret)
			//.scope("account.r,links.rw,usage.r,credentials.r")
			.scope(scope)
			.callback(HubicApi.CALLBACK_URL).build();

	Token accessToken = service.refreshAccessToken(expiredToken);	    
	return getSwiftAccess (service, accessToken) ;
}
 
Example #8
Source File: AuthenticationActivity.java    From FitbitAndroidSample with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_authentication);
	final WebView wvAuthorise = (WebView) findViewById(R.id.wvAuthorise);
	wvAuthorise.getSettings().setJavaScriptEnabled(true);
	wvAuthorise.addJavascriptInterface(new MyJavaScriptInterface(/*this*/), "HtmlViewer");
	wvAuthorise.setWebViewClient(new WebViewClient() {
           @Override
           public void onPageFinished(WebView view, String url) {
           	wvAuthorise.loadUrl("javascript:window.HtmlViewer.showHTML" +
                       "('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
           }
       });

	// Replace these with your own api key and secret
	String apiKey = "5dbccac0710c4d2ca0814f232beac1b5";
	String apiSecret = "f7e6a726b0eb49829816f75fccd30a54";

	MainActivity.service = new ServiceBuilder().provider(FitbitApi.class).apiKey(apiKey)
			.apiSecret(apiSecret).build();

	// network operation shouldn't run on main thread
	new Thread(new Runnable() {
		public void run() {
			MainActivity.requestToken = MainActivity.service.getRequestToken();
			final String authURL = MainActivity.service
					.getAuthorizationUrl(MainActivity.requestToken);

			// Webview nagivation should run on main thread again...
			wvAuthorise.post(new Runnable() {
				@Override
				public void run() {
					wvAuthorise.loadUrl(authURL);
				}
			});
		}
	}).start();
}
 
Example #9
Source File: XeroClient.java    From xero-java-client with Apache License 2.0 5 votes vote down vote up
public XeroClient(Reader pemReader, String consumerKey, String consumerSecret) {
  service = new ServiceBuilder()
      .provider(new XeroOAuthService(pemReader))
      .apiKey(consumerKey)
      .apiSecret(consumerSecret)
      .build();
  token = new Token(consumerKey, consumerSecret);
}
 
Example #10
Source File: MapzenApplication.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    graph = ObjectGraph.create(getModules().toArray());
    inject(this);

    if (simpleCrypt != null) {
        osmOauthService = new ServiceBuilder()
                .provider(OSMApi.class)
                .apiKey(simpleCrypt.decode(getString(R.string.osm_key)))
                .debug()
                .callback("mapzen://oauth-login/mapzen.com")
                .apiSecret(simpleCrypt.decode(getString(R.string.osm_secret))).build();
    }
}
 
Example #11
Source File: EvernoteOAuthActivity.java    From EverMemo with MIT License 5 votes vote down vote up
/**
 * 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: ResourceClient.java    From jerseyoauth2 with MIT License 5 votes vote down vote up
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 #13
Source File: EvernoteOAuthActivity.java    From EverMemo-EverNote with MIT License 5 votes vote down vote up
/**
 * 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 #14
Source File: SLIAuthenticationEntryPoint.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
@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 #15
Source File: RequestBuilder.java    From jumblr with Apache License 2.0 4 votes vote down vote up
public void setConsumer(String consumerKey, String consumerSecret) {
    service = new ServiceBuilder().
    provider(TumblrApi.class).
    apiKey(consumerKey).apiSecret(consumerSecret).
    build();
}