当前位置: 首页>>代码示例>>Java>>正文


Java OAuthService类代码示例

本文整理汇总了Java中com.github.scribejava.core.oauth.OAuthService的典型用法代码示例。如果您正苦于以下问题:Java OAuthService类的具体用法?Java OAuthService怎么用?Java OAuthService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OAuthService类属于com.github.scribejava.core.oauth包,在下文中一共展示了OAuthService类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadOAuthProviderAccount

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
public OAuthProviderAccount loadOAuthProviderAccount(Token accessToken, OAuthProviderName provider) {
	OAuthService service = this.getService();

	// getting user profile
	OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, config.getProfileUrl(), service);
	service.signRequest(accessToken, oauthRequest); // the access token from step 4

	Response oauthResponse = oauthRequest.send();

	String jsonString = oauthResponse.getBody();
	JSONObject root = new JSONObject(jsonString);

	String accountId = String.valueOf(root.getInt(TWITTER_ACCTID_PROPERTY)); 
	String displayName = root.getString(TWITTER_DISPLAYNAME_PROPERTY);
	String publicId = root.getString(TWITTER_SCREENNAME_PROPERTY); 
	String profilePath = provider.getIdProviderUrl() + "/" + publicId; 
	
	OAuthProviderAccount profile = 
			new OAuthProviderAccount(accessToken, provider, displayName, accountId, publicId , profilePath);

	return profile;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:23,代码来源:TwitterOAuthProvider.java

示例2: getService

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
/**
 * Gets the OAuth Service.
 *
 * @return the OAuth Service
 */
@SuppressWarnings("unchecked")
public OAuthService getService() {
	if (this.service == null){
		if (config.getScope().length()>0){
			this.service = new ServiceBuilder().provider(config.getApiClass())
					.apiKey(config.getApiKey())
				    .apiSecret(config.getApiSecret())
				    .callback(config.getCallback())
				    .scope(config.getScope())
				    .build();				
		}
		else {
			this.service = new ServiceBuilder().provider(config.getApiClass())
					.apiKey(config.getApiKey())
				    .apiSecret(config.getApiSecret())
				    .callback(config.getCallback())
				    .build();							
		}
	}
	return service;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:27,代码来源:OAuthProvider.java

示例3: loadOAuthProviderAccount

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
public OAuthProviderAccount loadOAuthProviderAccount(Token accessToken, OAuthProviderName provider) {

	OAuthService service = this.getService();

	// getting user profile
	OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, config.getProfileUrl(), service);

	service.signRequest(accessToken, oauthRequest);
	Response oauthResponse = oauthRequest.send();
	String jsonString = oauthResponse.getBody();
	JSONObject root = new JSONObject(jsonString);
	JSONArray emailArray = root.getJSONArray(GOOGLE_JSON_EMAILLIST_PROPERTY);
	JSONObject firstEmail = emailArray.getJSONObject(0);

	String accountId = root.getString(GOOGLE_JSON_ACCOUNTID_PROPERTY); 
	String displayName = root.getString(GOOGLE_JSON_DISPLAYNAME_PROPERTY);
	String publicId = firstEmail.getString(GOOGLE_JSON_EMAIL_PROPERTY); 
	String profilePath="";
	if (root.has(GOOGLE_JSON_PROFILEPATH_PROPERTY)){
		profilePath = root.getString(GOOGLE_JSON_PROFILEPATH_PROPERTY); 
	}
	
	OAuthProviderAccount profile = 
			new OAuthProviderAccount(accessToken, provider, displayName, accountId, publicId , profilePath);
		
	return profile;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:28,代码来源:GoogleOAuthProvider.java

示例4: callback

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
@Override
public void callback(CallbackContext context) {
    HttpServletRequest request = context.getRequest();
    OAuthService scribe = prepareScribe(context).build();
    String oAuthVerifier = request.getParameter("code");

    Token accessToken = scribe.getAccessToken(EMPTY_TOKEN, new Verifier(oAuthVerifier));

    OAuthRequest userRequest = new OAuthRequest(Verb.GET, gitLabConfiguration.url() + "/api/" + gitLabConfiguration.apiVersion() + "/user", scribe);
    scribe.signRequest(accessToken, userRequest);

    com.github.scribejava.core.model.Response userResponse = userRequest.send();
    if (!userResponse.isSuccessful()) {
        throw new IllegalStateException(format("Fail to authenticate the user. Error code is %s, Body of the response is %s", userResponse.getCode(), userResponse.getBody()));
    }
    String userResponseBody = userResponse.getBody();
    LOGGER.trace("User response received : %s", userResponseBody);
    GsonUser gsonUser = GsonUser.parse(userResponseBody);

    UserIdentity.Builder builder = UserIdentity.builder().setProviderLogin(gsonUser.getUsername()).setLogin(gsonUser.getUsername()).setName(gsonUser.getName()).setEmail(gsonUser.getEmail());
    if (!gitLabConfiguration.userExceptions().contains(gsonUser.getUsername())) {
        Set<String> groups = getUserGroups(accessToken);
        if (!groups.isEmpty()) {
            builder.setGroups(groups);
        }
    }

    context.authenticate(builder.build());
    context.redirectToRequestedPage();
}
 
开发者ID:gabrie-allaigre,项目名称:sonar-auth-gitlab-plugin,代码行数:31,代码来源:GitLabIdentityProvider.java

示例5: main

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
public static void main(String[] args) {

        // Replace these with your client id and secret
        final String clientId = "your client id";
        final String clientSecret = "your client secret";

        final OAuthService service = new ServiceBuilder()
                .provider(StravaOAuth2Api.class)
                .apiKey(clientId)
                .apiSecret(clientSecret)
                .callback("http://localhost:8080/oauth/callback")
                .build();

        final Scanner in = new Scanner(System.in, "UTF-8");

        // Obtain the Authorization URL
        final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);

        System.out.println("Go to authorization URL:");
        System.out.println(authorizationUrl);
        System.out.println("Copy/paste the authorization code here");
        System.out.print(">>");
        final Verifier verifier = new Verifier(in.nextLine());
        System.out.println();

        System.out.println("Trading the Request Token for an Access Token...");
        final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
        System.out.println("Got the Access Token!");
        System.out.println("(if your curious it looks like this: " + accessToken + " )");
    }
 
开发者ID:tiberiu-biking,项目名称:scribejava-strava,代码行数:31,代码来源:StravaOAuth2ApiTest.java

示例6: getOAuthService

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
@Override
public OAuthService getOAuthService()
{
    //@formatter:off
    return new ServiceBuilder()
            .apiKey(clientId)
            .apiSecret(clientSecret)
            .scope(scope)
            .state("secret"+ new Random().nextInt(999_99))
            .callback(callbackUrl)
            .grantType("authorization_code")
            .build(new ScribeApi20Impl(loginUrl, tokenUrl));
    //@formatter:on
}
 
开发者ID:timpanogos,项目名称:crestj,代码行数:15,代码来源:CrestAuthenticator.java

示例7: createOAuthService

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
/**
 * Creates an OAuthService for authentication a user with OAuth
 *
 * @param oAuthProvider The OAuth provider Enum
 * @return An Optional OAuthService
 */
public Optional<OAuthService> createOAuthService(OAuthProvider oAuthProvider) {
    Objects.requireNonNull(oAuthProvider, Required.OAUTH_PROVIDER.toString());

    Config config = Application.getInstance(Config.class);
    OAuthService oAuthService = null;
    switch (oAuthProvider) {
    case TWITTER:
        oAuthService = new ServiceBuilder(config.getString(Key.OAUTH_TWITTER_KEY))
        .callback(config.getString(Key.OAUTH_TWITTER_CALLBACK))
        .apiSecret(config.getString(Key.OAUTH_TWITTER_SECRET))
        .build(TwitterApi.instance());
        break;
    case GOOGLE:
        oAuthService = new ServiceBuilder(config.getString(Key.OAUTH_GOOGLE_KEY))
        .scope(SCOPE)
        .callback(config.getString(Key.OAUTH_GOOGLE_CALLBACK))
        .apiSecret(config.getString(Key.OAUTH_GOOGLE_SECRET))
        .state("secret" + new SecureRandom().nextInt(MAX_RANDOM))
        .build(GoogleApi20.instance());
        break;
    case FACEBOOK:
        oAuthService = new ServiceBuilder(config.getString(Key.OAUTH_FACEBOOK_KEY))
        .callback(config.getString(Key.OAUTH_FACEBOOK_CALLBACK))
        .apiSecret(config.getString(Key.OAUTH_FACEBOOK_SECRET))
        .build(FacebookApi.instance());
        break;
    default:
        break;
    }

    return (oAuthService == null) ? Optional.empty() : Optional.of(oAuthService);
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:39,代码来源:RequestHelper.java

示例8: execute

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
@Override
public Response execute(Request request, Response response) {
    Optional<OAuthProvider> oAuthProvider = this.requestHelper.getOAuthProvider(request.getParameter(Default.OAUTH_REQUEST_PARAMETER.toString()));
    if (oAuthProvider.isPresent()) {
        Optional<OAuthService> oAuthService = this.requestHelper.createOAuthService(oAuthProvider.get());
        if (oAuthService.isPresent()) {
            String url = null;
            switch (oAuthProvider.get()) {
                case TWITTER:
                    url = getTwitterUrl((OAuth10aService) oAuthService.get());
                    break;
                case GOOGLE:
                case FACEBOOK:
                    url = getOAuth2Url((OAuth20Service) oAuthService.get());
                    break;
                default:
                break;
            }

            if (StringUtils.isNotBlank(url)) {
                return Response.withRedirect(URI.create(url).toString()).end();
            }
        }
    }

    return response;
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:28,代码来源:OAuthLoginFilter.java

示例9: createService

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
@Override
public OAuthService createService(OAuthConfig config) {
    return new SlackOAuth20ServiceImpl(this, config);
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:5,代码来源:SlackApi.java

示例10: init

import com.github.scribejava.core.oauth.OAuthService; //导入依赖的package包/类
@Override
public void init(InitContext context) {
    OAuthService scribe = prepareScribe(context).build();
    String url = scribe.getAuthorizationUrl(EMPTY_TOKEN);
    context.redirectTo(url);
}
 
开发者ID:gabrie-allaigre,项目名称:sonar-auth-gitlab-plugin,代码行数:7,代码来源:GitLabIdentityProvider.java


注:本文中的com.github.scribejava.core.oauth.OAuthService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。