當前位置: 首頁>>代碼示例>>Java>>正文


Java OAuthService.getAccessToken方法代碼示例

本文整理匯總了Java中org.scribe.oauth.OAuthService.getAccessToken方法的典型用法代碼示例。如果您正苦於以下問題:Java OAuthService.getAccessToken方法的具體用法?Java OAuthService.getAccessToken怎麽用?Java OAuthService.getAccessToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.scribe.oauth.OAuthService的用法示例。


在下文中一共展示了OAuthService.getAccessToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAccessToken

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Override
protected String getAccessToken()
{
    Verifier verifier = new Verifier(request.getParameter("oauth_verifier"));
    Token requestToken = (Token) request.getSession().getAttribute("requestToken");
    request.getSession().removeAttribute("requestToken");

    OAuthService service = createOAuthScribeService();
    Token accessTokenObj = null;
    try
    {
        accessTokenObj = service.getAccessToken(requestToken, verifier);
    } catch (OAuthConnectionException e)
    {
        Organization organizationInstance = organizationService.get(Integer.parseInt(organization), false);
        throw new SourceControlException("Error obtaining access token. Cannot access " + organizationInstance.getHostUrl() + " from Jira.", e);
    } finally
    {
        httpClientProvider.closeIdleConnections();
    }

    return BitbucketOAuthAuthentication.generateAccessTokenString(accessTokenObj);
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:24,代碼來源:RegenerateBitbucketOauthToken.java

示例2: doFinish

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
public String doFinish()
{
    // now get the access token
    Verifier verifier = new Verifier(request.getParameter("oauth_verifier"));
    Token requestToken = (Token) request.getSession().getAttribute(SESSION_KEY_REQUEST_TOKEN);

    if (requestToken == null)
    {
        log.debug("Request token is NULL. It has been removed in the previous attempt of adding organization. Now we will stop.");
        return getRedirect("ConfigureDvcsOrganizations.jspa?atl_token=" + CustomStringUtils.encode(getXsrfToken()));
    }

    request.getSession().removeAttribute(SESSION_KEY_REQUEST_TOKEN);

    OAuthService service = createOAuthScribeService();
    Token accessTokenObj = service.getAccessToken(requestToken, verifier);
    accessToken = BitbucketOAuthAuthentication.generateAccessTokenString(accessTokenObj);

    httpClientProvider.closeIdleConnections();

    return doAddOrganization();
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:23,代碼來源:AddBitbucketOrganization.java

示例3: getUserInfoJSON

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
private JSONObject getUserInfoJSON(String code, String callBackUrl) {
    OAuthService service = new ServiceBuilder()
            .provider(FacebookApi.class)
            .apiKey(apiKey)
            .apiSecret(apiSecret)
            .callback(host + callBackUrl)
            .scope("email")
            .build();
    Verifier verifier = new Verifier(code);
    Token accessToken = service.getAccessToken(NULL_TOKEN, verifier);
    OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
    request.addOAuthParameter("scope", "email");
    service.signRequest(accessToken, request);
    Response response = request.send();
    LOG.info("response body is " + response.getBody());
    try {
        JSONObject obj = new JSONObject(response.getBody());
        obj.put("access_token", accessToken.getToken());
        return obj;
    } catch (JSONException e) {
        return new JSONObject();
    }
}
 
開發者ID:cilogi,項目名稱:lid,代碼行數:24,代碼來源:FacebookLoginServlet.java

示例4: doAuth

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Override
protected void doAuth( Intent intent )
{
    final String code = intent.getStringExtra( SitesLoginHandler.VERIFIER_KEY );
    Token accessToken = null;
    String userName = null;
    try
    {
        OAuthService service = new ServiceBuilder()
                .provider( InstagramApi.class )
                .callback( InstagramLoginActivity.CALLBACK_URL )
                .apiKey( InstagramConfig.INSTAGRAM_CLIENT_ID )
                .apiSecret( InstagramConfig.INSTAGRAM_CLIENT_SECRET )
                .scope( InstagramConfig.INSTAGRAM_SCOPE )
                .build();
        accessToken = service.getAccessToken( null, new Verifier( code ) );
        userName = Helper.extractInstagramUserName( accessToken.getRawResponse() );
    }
    catch ( Exception e )
    {
        Helper.debug( "Error while obtaining Instagram access token : " + e.getMessage() );
    }
    boolean success = null != accessToken;
    // Subscriber : InstagramLoginHandler : onInstagramAuthDone()
    HashtaggerApp.bus.post( new InstagramAuthDoneEvent( success, accessToken, userName ) );
}
 
開發者ID:iTwenty,項目名稱:Hashtagger,代碼行數:27,代碼來源:InstagramService.java

示例5: authorize

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
private Token authorize() {
	OAuthService service = new ServiceBuilder()
			.provider(CubeSensorsAuthApi.class)
			.apiKey(CubeSensorsProperties.getAppKey())
			.apiSecret(CubeSensorsProperties.getAppSecret())
			.signatureType(SignatureType.QueryString).build();

	Token requestToken = service.getRequestToken();
	String authorizationUrl = service.getAuthorizationUrl(requestToken);

	String authorization = authProvider.getAuthorization(authorizationUrl);

	Token accessToken = service.getAccessToken(requestToken, new Verifier(
			authorization));

	return accessToken;
}
 
開發者ID:1337joe,項目名稱:cubesensors-for-java,代碼行數:18,代碼來源:CubeSensorsUtils.java

示例6: obtainsAccessToken

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
/**
 * Odesk access token can be obtained through OAuth.
 * @throws Exception If some problem inside
 */
@Test
public void obtainsAccessToken() throws Exception {
    Assume.assumeThat(RtOdeskOauthExample.KEY, Matchers.notNullValue());
    final OAuthService service = new ServiceBuilder()
        .provider(OAuthWire.OdeskApi.class)
        .apiKey(RtOdeskOauthExample.KEY)
        .apiSecret(RtOdeskOauthExample.SECRET)
        .build();
    final Token rqst = service.getRequestToken();
    Logger.info(
        this, "authorization URL: %s (open it in a browser)",
        service.getAuthorizationUrl(rqst)
    );
    Logger.info(this, "enter Odesk verifier and press ENTER:");
    final Scanner input = new Scanner(System.in);
    final Verifier verifier = new Verifier(input.nextLine());
    final Token access = service.getAccessToken(rqst, verifier);
    Logger.info(this, "access token is: %s", access.getToken());
    Logger.info(this, "access token secret is: %s", access.getSecret());
}
 
開發者ID:jcabi,項目名稱:jcabi-odesk,代碼行數:25,代碼來源:RtOdeskOauthExample.java

示例7: main

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    System.out.println("Paste the consumerKey here");
    System.out.print(">>");
    String apiKey = in.nextLine();

    System.out.println("Paste the consumerSecret here");
    System.out.print(">>");
    String apiSecret = in.nextLine();

    OAuthService service = new ServiceBuilder()
        .provider(YammerApi.class)
        .apiKey(apiKey)
        .apiSecret(apiSecret)
        .build();

    String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
    System.out
            .println("Go and authorize your app here (eg. in a web browser):");
    System.out.println(authorizationUrl);
    System.out.println("... and paste the authorization code here");
    System.out.print(">>");
    Verifier verifier = new Verifier(in.nextLine());

    System.out.println();

    Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
    System.out.println("Your Access Token is: " + accessToken);
    System.out.println();

    in.close();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:34,代碼來源:YammerAccessCodeGenerator.java

示例8: doAccessAuth

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
private TwitterAuthDoneEvent doAccessAuth( Token requestToken, String oauthVerifier )
{
    Token accessToken = null;
    String userName = null;
    try
    {
        OAuthService service = new ServiceBuilder()
                .provider( TwitterApi.SSL.class )
                .callback( TwitterLoginActivity.TWITTER_CALLBACK_URL )
                .apiKey( TwitterConfig.TWITTER_OAUTH_CONSUMER_KEY )
                .apiSecret( TwitterConfig.TWITTER_OAUTH_CONSUMER_SECRET )
                .build();
        accessToken = service.getAccessToken( requestToken, new Verifier( oauthVerifier ) );

        // Once we have the access token, we do a quick and dirty request to get the username
        OAuthRequest request = new OAuthRequest( Verb.GET, TWITTER_USERNAME_URL );
        service.signRequest( accessToken, request );
        Response response = request.send();
        userName = Helper.extractJsonStringField( response.getBody(), "name" );
    }
    catch ( Exception e )
    {
        Helper.debug( "Error while obtaining twitter access token : " + e.getMessage() );
    }
    boolean success = null != accessToken;
    return new TwitterAuthDoneEvent( success, accessToken, userName, null, AuthType.ACCESS );
}
 
開發者ID:iTwenty,項目名稱:Hashtagger,代碼行數:28,代碼來源:TwitterService.java

示例9: doAuth

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Override
protected void doAuth( Intent intent )
{
    final String code = intent.getStringExtra( SitesLoginHandler.VERIFIER_KEY );
    Token accessToken = null;
    String userName = null;
    try
    {
        OAuthService service = new ServiceBuilder()
                .callback( FacebookLoginActivity.FACEBOOK_CALLBACK_URL )
                .provider( FacebookApi.class )
                .apiKey( FacebookConfig.FACEBOOK_OAUTH_APP_ID )
                .apiSecret( FacebookConfig.FACEBOOK_OAUTH_APP_SECRET )
                .build();
        accessToken = service.getAccessToken( null, new Verifier( code ) );
        OAuthRequest request = new OAuthRequest( Verb.GET, FACEBOOK_USERNAME_URL );
        service.signRequest( accessToken, request );
        Response response = request.send();
        userName = Helper.extractJsonStringField( response.getBody(), "name" );
    }
    catch ( Exception e )
    {
        Helper.debug( "Failed to get Facebook access token : " + e.getMessage() );
    }
    boolean success = null != accessToken;
    // Subscriber : FacebookLoginHandler : onFacebookAuthDone()
    HashtaggerApp.bus.post( new FacebookAuthDoneEvent( success, accessToken, userName ) );
}
 
開發者ID:iTwenty,項目名稱:Hashtagger,代碼行數:29,代碼來源:FacebookService.java

示例10: doAuth

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Override
protected void doAuth( Intent authIntent )
{
    final String code = authIntent.getStringExtra( SitesLoginHandler.VERIFIER_KEY );
    Token accessToken = null;
    String userName = null;
    try
    {
        OAuthService service = new ServiceBuilder()
                .provider( Google2Api.class )
                .callback( GPlusLoginActivity.GPLUS_CALLBACK_URL )
                .apiKey( GPlusConfig.GPLUS_OAUTH_CLIENT_ID )
                .apiSecret( GPlusConfig.GPLUS_OAUTH_CLIENT_SECRET )
                .scope( GPlusConfig.GPLUS_ACCESS_SCOPE )
                .build();
        accessToken = service.getAccessToken( null, new Verifier( code ) );
        OAuthRequest request = new OAuthRequest( Verb.GET, GPLUS_USERNAME_URL );
        service.signRequest( accessToken, request );
        Response response = request.send();
        userName = Helper.extractJsonStringField( response.getBody(), "displayName" );
    }
    catch ( Exception e )
    {
        Helper.debug( "Error while obtaining Google+ access token : " + e.getMessage() );
    }
    boolean success = null != accessToken;
    // Subscriber : GPlusLoginHandler : onGPlusAuthDone()
    HashtaggerApp.bus.post( new GPlusAuthDoneEvent( success, accessToken, userName ) );
}
 
開發者ID:iTwenty,項目名稱:Hashtagger,代碼行數:30,代碼來源:GPlusService.java

示例11: authorize

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Test
@Ignore("Not suitable as automatic unit test. Requires manual action.")
public void authorize() throws URISyntaxException, IOException {
    final String key = System.getProperty("key");
    final String secret = System.getProperty("secret");
    assertNotNull("You must use a discogs key via System property -Dkey=", key);
    assertNotNull("You must use a discogs secret via System property -Dsecret=", secret);
    assertNotNull("You must use a custom user agent via System property -Dhttp.agent=", System.getProperty("http.agent"));
    final OAuthService service = new ServiceBuilder()
            .provider(DiscogsApi.class)
            .apiKey(key)
            .apiSecret(secret)
            .debug()
            .build();
    final Token requestToken = service.getRequestToken();
    System.out.println("Token: " + requestToken);
    final String authorizationUrl = service.getAuthorizationUrl(requestToken);
    System.out.println("AuthorizationUrl: " + authorizationUrl);

    Desktop.getDesktop().browse(new URI(authorizationUrl));
    System.out.println("Please enter token: ");
    final String token = System.console().readLine();
    System.out.println("Got " + token);
    final Verifier verifier = new Verifier(token);

    // Trade the Request Token and Verifier for the Access Token
    final Token accessToken = service.getAccessToken(requestToken, verifier);

    final OAuthRequest request = new OAuthRequest(Verb.GET, "https://api.discogs.com/image/R-944131-1175701834.jpeg");
    service.signRequest(accessToken, request);
    final Response response = request.send();
    System.out.println(response.getCode() + " " + response.getMessage());
}
 
開發者ID:hendriks73,項目名稱:coxy,代碼行數:34,代碼來源:DiscogsApiTest.java

示例12: auth

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
public String auth(final Shell shell) throws MalformedURLException, InterruptedException {
    try {
        Class<? extends EvernoteApi> apiClass = EvernoteUtil.brand().scribeOAuthApi();
        OAuthService service = new ServiceBuilder().provider(apiClass).apiKey(CONSUMER_KEY).apiSecret(EncryptionUtil.decrypt(CONSUMER_SECRET)).callback(callback.getCallbackURL()).build();
        Token requestToken = service.getRequestToken();
        String authUrl = service.getAuthorizationUrl(requestToken);
        try {
            PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(authUrl));
        } catch (PartInitException couldNotOpenBrowser) {
            LinkedHashMap<String, String> btns = MapUtil.orderedMap();
            btns.put(Constants.Plugin_OAuth_Copy, Messages.Plugin_OAuth_Copy);
            btns.put(Constants.Plugin_OAuth_Cancel, Messages.Plugin_OAuth_Cancel);

            String opt = new SyncEclipseUtil().openCustomImageTypeWithCustomButtonsSyncly(shell, Messages.Plugin_OAuth_Title, Messages.Plugin_OAuth_DoItManually, new Image(Display.getDefault(), getClass().getClassLoader().getResourceAsStream(Constants.OAUTH_EVERNOTE_TRADEMARK)), btns);
            if (Constants.Plugin_OAuth_Copy.equals(opt)) {
                ClipboardUtil.copy(authUrl);
            } else {
                return StringUtils.EMPTY;
            }
        }

        // wait for callback handling
        synchronized (callback) {
            callback.wait(30 * 60 * 1000);// 30 minutes
        }

        String verifierValue = callback.getVerifier();
        if (StringUtils.isBlank(verifierValue)) {
            return StringUtils.EMPTY;
        }
        Verifier verifier = new Verifier(verifierValue);
        Token accessToken = service.getAccessToken(requestToken, verifier);
        return accessToken.getToken();
    } finally {
        callback.done();
    }
}
 
開發者ID:LTTPP,項目名稱:Eemory,代碼行數:38,代碼來源:OAuth.java

示例13: getAccessToken

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Background
protected void getAccessToken(final OAuthService service,
                              final Token requestToken, final String url) {
    final Uri uri = Uri.parse(url);
    final String verifier = uri.getQueryParameter("oauth_verifier");
    final String username = uri.getQueryParameter("username");
    final Verifier v = new Verifier(verifier);

    try {
        final Token accessToken = service.getAccessToken(requestToken, v);

        prefs.username().put(username);
        prefs.accessToken().put(accessToken.getToken());
        prefs.accessSecret().put(accessToken.getSecret());
        prefs.requestToken().put(requestToken.getToken());

        final Intent result = new Intent();
        result.putExtra(EXTRA_USERNAME, username);
        result.putExtra(EXTRA_ACCESSTOKEN, accessToken.getToken());
        result.putExtra(EXTRA_ACCESSSECRET, accessToken.getSecret());
        result.putExtra(EXTRA_REQUESTTOKEN, requestToken.getToken());
        setResult(Activity.RESULT_OK, result);
        finish();
    } catch (OAuthException e) {
        reportOAuthError();
    }
}
 
開發者ID:KoljaTM,項目名稱:Yarrn,代碼行數:28,代碼來源:GetAccessTokenActivity.java

示例14: verifyingAuthentication

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
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());
    }
}
 
開發者ID:inbloom,項目名稱:secure-data-service,代碼行數:16,代碼來源:SLIAuthenticationEntryPoint.java

示例15: main

import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
public static void main(String[] args)
{
  OAuthService service = new ServiceBuilder()
                              .provider(MeetupApi.class)
                              .apiKey("j1khkp0dus323ftve0sdcv6ffe")
                              .apiSecret("6s6gt6q59gvfjtsvgcmht62gq4")
                              .build();
  Scanner in = new Scanner(System.in);

  System.out.println("=== Meetup's OAuth Workflow ===");
  System.out.println();

  // Obtain the Request Token
  System.out.println("Fetching the Request Token...");
  Token requestToken = service.getRequestToken();
  System.out.println("Got the Request Token!");
  System.out.println();

  System.out.println("Now go and authorize Scribe here:");
  System.out.println(service.getAuthorizationUrl(requestToken));
  System.out.println("And paste the verifier here");
  System.out.print(">>");
  Verifier verifier = new Verifier(in.nextLine());
  System.out.println();

  // Trade the Request Token and Verfier for the Access Token
  System.out.println("Trading the Request Token for an Access Token...");
  Token accessToken = service.getAccessToken(requestToken, verifier);
  System.out.println("Got the Access Token!");
  System.out.println("(if your curious it looks like this: " + accessToken + " )");
  System.out.println();

  // Now let's go and ask for a protected resource!
  System.out.println("Now we're going to access a protected resource...");
  OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
  service.signRequest(accessToken, request);
  Response response = request.send();
  System.out.println("Got it! Lets see what we found...");
  System.out.println();
  System.out.println(response.getBody());

  System.out.println();
  System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
 
開發者ID:visun,項目名稱:scribeoauth,代碼行數:45,代碼來源:MeetupExample.java


注:本文中的org.scribe.oauth.OAuthService.getAccessToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。