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


Java OAuthService.signRequest方法代码示例

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


在下文中一共展示了OAuthService.signRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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


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