当前位置: 首页>>代码示例>>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;未经允许,请勿转载。