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


Java OAuthService類代碼示例

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


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

示例1: redirectUserToGrantAccess

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
@Override
protected String redirectUserToGrantAccess()
{
    try
    {
        OAuthService service = createOAuthScribeService();
        Token requestToken = service.getRequestToken();
        String authUrl = service.getAuthorizationUrl(requestToken);

        request.getSession().setAttribute("requestToken", requestToken);

        return SystemUtils.getRedirect(this, authUrl, true);

    } catch (Exception e)
    {
        addErrorMessage("Cannot proceed authentication, check OAuth credentials for account " + getOrganizationName());
        return INPUT;
    }
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:20,代碼來源:RegenerateBitbucketOauthToken.java

示例2: createBitbucketOAuthScribeService

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
private OAuthService createBitbucketOAuthScribeService(String callbackUrl)
{
    Organization organizationInstance = organizationService.get(Integer.parseInt(organization), false);

    ServiceBuilder sb = new ServiceBuilder().apiKey(organizationInstance.getCredential().getOauthKey())
            .signatureType(SignatureType.Header).apiSecret(organizationInstance.getCredential().getOauthSecret())
            .provider(new Bitbucket10aScribeApi(organizationInstance.getHostUrl(), httpClientProvider))
            .debugStream(new DebugOutputStream(log));

    if (!StringUtils.isBlank(callbackUrl))
    {
        sb.callback(callbackUrl);
    }

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

示例3: redirectUserToBitbucket

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
private String redirectUserToBitbucket()
{
    try
    {
        OAuthService service = createOAuthScribeService();
        Token requestToken = service.getRequestToken();
        String authUrl = service.getAuthorizationUrl(requestToken);

        request.getSession().setAttribute(SESSION_KEY_REQUEST_TOKEN, requestToken);

        return SystemUtils.getRedirect(this, authUrl, true);
    }
    catch (Exception e)
    {
        log.warn("Error redirect user to bitbucket server.", e);
        addErrorMessage("The authentication with Bitbucket has failed. Please check your OAuth settings.");
        triggerAddFailedEvent(FAILED_REASON_OAUTH_TOKEN);
        return INPUT;
    }
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:21,代碼來源:AddBitbucketOrganization.java

示例4: 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

示例5: 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

示例6: afterFinalUriConstructed

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
@Override
protected String afterFinalUriConstructed(HttpRequestBase forMethod, String finalUri, Map<String, ? extends Object> parameters)
{
    long start = System.currentTimeMillis();
	//
	// generate oauth 1.0 params for 2LO - use scribe so far for that ...
	//
	OAuthService service = createOauthService();
	OAuthRequest request = new OAuthRequest(Verb.valueOf(forMethod.getMethod()), finalUri);

	addParametersForSigning(request, parameters);

	service.signRequest(new EmptyToken(), request);
	Map<String, String> oauthParams = request.getOauthParameters();
	//
	//
	log.debug("2LO signing took [{}] ms ", System.currentTimeMillis() - start);

	return finalUri + paramsToString(oauthParams, finalUri.indexOf("?") != -1);
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:21,代碼來源:TwoLegged10aOauthRemoteRequestor.java

示例7: onConnectionCreated

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
@Override
protected void onConnectionCreated(HttpClient client, HttpRequestBase method, Map<String, ? extends Object> parameters)
        throws IOException
{
    long start = System.currentTimeMillis();
    //
    // generate oauth 1.0 params for 3LO - use scribe so far for that ...
    //
    OAuthService service = createOauthService();
    OAuthRequest request = new OAuthRequest(Verb.valueOf(method.getMethod()), method.getURI().toString());

    addParametersForSigning(request, parameters);

    service.signRequest(generateAccessTokenObject(accessTokenWithSecret), request);

    String header = authHeaderCreator.extract(request);
    method.addHeader(OAuthConstants.HEADER, header);

    log.debug("3LO signing took [{}] ms ", System.currentTimeMillis() - start);
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:21,代碼來源:ThreeLegged10aOauthRemoteRequestor.java

示例8: 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

示例9: provideOAuthService

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
@Singleton
@Provides
public OAuthService provideOAuthService() {
	ServiceBuilder serviceBuilder = new ServiceBuilder()
					.apiKey(BuildConfig.GEOCACHING_API_KEY)
					.apiSecret(BuildConfig.GEOCACHING_API_SECRET)
					.callback(AppConstants.OAUTH_CALLBACK_URL)
					.debug();

	if (BuildConfig.GEOCACHING_API_STAGING) {
		serviceBuilder.provider(GeocachingOAuthProvider.Staging.class);
	} else {
		serviceBuilder.provider(GeocachingOAuthProvider.class);
	}

	return serviceBuilder.build();
}
 
開發者ID:arcao,項目名稱:Trackables,代碼行數:18,代碼來源:GeocachingModule.java

示例10: oAuth

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
private void oAuth() {
    // Replace these with your own api key and secret
    OAuthService service = FlickrForPalabreApplication.getoAuthService();
    Token mRequestToken = FlickrForPalabreApplication.getRequestToken();

    if (mRequestToken == null) {
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(MainActivity.this, getString(R.string.oauth_connection_error), Toast.LENGTH_LONG).show();
            }
        });
        return;
    }

    final String authorizationUrl = service.getAuthorizationUrl(mRequestToken);
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
    editor.putString(SharedPreferenceKeys.TOKEN_TOKEN, mRequestToken.getToken())
            .putString(SharedPreferenceKeys.TOKEN_SECRET, mRequestToken.getSecret())
            .putString(SharedPreferenceKeys.TOKEN_RESPONSE, mRequestToken.getRawResponse())
            .apply();

    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authorizationUrl)));

}
 
開發者ID:levelup,項目名稱:palabre-extensions,代碼行數:26,代碼來源:MainActivity.java

示例11: createService

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
@Override
public OAuthService createService(final OAuthConfig config) {
    return new OAuth20ServiceImpl(this, config) {
        @Override
        public Token getAccessToken(Token requestToken, Verifier verifier) {
            //basic auth, as described at https://developer.atlassian.com/static/bitbucket/concepts/oauth2.html
            OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), getAccessTokenEndpoint());

            //basic auth
            request.addHeader("Authorization", "Basic "+Base64Encoder.getInstance().encode((config.getApiKey()+":"+config.getApiSecret()).getBytes(StandardCharsets.UTF_8)));

            request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
            request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());

            request.addBodyParameter("grant_type", "authorization_code");
            Response response = request.send();
            return getAccessTokenExtractor().extract(response.getBody());
        }
    };
}
 
開發者ID:digitalfondue,項目名稱:lavagna,代碼行數:21,代碼來源:Bitbucket20Api.java

示例12: createService

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
@Override
public OAuthService createService(final OAuthConfig config) {
	return new OAuth20ServiceImpl(this, config) {
		@Override
		public Token getAccessToken(Token requestToken, Verifier verifier) {
			OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), getAccessTokenEndpoint());
			request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
			request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
			request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
			request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
			request.addBodyParameter("grant_type", "authorization_code");
			if (config.hasScope()) {
				request.addBodyParameter(OAuthConstants.SCOPE, config.getScope());
			}
			Response response = request.send();
			return getAccessTokenExtractor().extract(response.getBody());
		}
	};
}
 
開發者ID:digitalfondue,項目名稱:lavagna,代碼行數:20,代碼來源:Google20Api.java

示例13: createService

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
@Override
public OAuthService createService(final OAuthConfig config) {
    return new OAuth20ServiceImpl(this, config) {
        @Override
        public Token getAccessToken(Token requestToken, Verifier verifier) {
            OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), getAccessTokenEndpoint());
            request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
            request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
            request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
            request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
            // well, the doc is not correct, see https://github.com/gitlabhq/gitlabhq/issues/9141
            request.addBodyParameter("grant_type", "authorization_code");
            Response response = request.send();
            return getAccessTokenExtractor().extract(response.getBody());
        }
    };
}
 
開發者ID:digitalfondue,項目名稱:lavagna,代碼行數:18,代碼來源:Gitlab20Api.java

示例14: doRequestAuth

import org.scribe.oauth.OAuthService; //導入依賴的package包/類
private TwitterAuthDoneEvent doRequestAuth()
{
    Token token = null;
    String authUrl = 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();
        token = service.getRequestToken();
        authUrl = service.getAuthorizationUrl( token );
    }
    catch ( OAuthConnectionException e )
    {
        Helper.debug( "Error while obtaining twitter request token : " + e.getMessage() );
    }
    boolean success = null != token;
    return new TwitterAuthDoneEvent( success, token, null, authUrl, AuthType.REQUEST );
}
 
開發者ID:iTwenty,項目名稱:Hashtagger,代碼行數:23,代碼來源:TwitterService.java

示例15: 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


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