Java Code Examples for me.zhyd.oauth.model.AuthToken#getAccessToken()
The following examples show how to use
me.zhyd.oauth.model.AuthToken#getAccessToken() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthMicrosoftRequest.java From JustAuth with MIT License | 6 votes |
@Override protected AuthUser getUserInfo(AuthToken authToken) { String token = authToken.getAccessToken(); String tokenType = authToken.getTokenType(); String jwt = tokenType + " " + token; HttpHeader httpHeader = new HttpHeader(); httpHeader.add("Authorization", jwt); String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false); JSONObject object = JSONObject.parseObject(userInfo); this.checkResponse(object); return AuthUser.builder() .rawUserInfo(object) .uuid(object.getString("id")) .username(object.getString("userPrincipalName")) .nickname(object.getString("displayName")) .location(object.getString("officeLocation")) .email(object.getString("mail")) .gender(AuthUserGender.UNKNOWN) .token(authToken) .source(source.toString()) .build(); }
Example 2
Source File: AuthAlipayRequest.java From JustAuth with MIT License | 5 votes |
@Override protected AuthUser getUserInfo(AuthToken authToken) { String accessToken = authToken.getAccessToken(); AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest(); AlipayUserInfoShareResponse response = null; try { response = this.alipayClient.execute(request, accessToken); } catch (AlipayApiException e) { throw new AuthException(e.getErrMsg(), e); } if (!response.isSuccess()) { throw new AuthException(response.getSubMsg()); } String province = response.getProvince(), city = response.getCity(); String location = String.format("%s %s", StringUtils.isEmpty(province) ? "" : province, StringUtils.isEmpty(city) ? "" : city); return AuthUser.builder() .rawUserInfo(JSONObject.parseObject(JSONObject.toJSONString(response))) .uuid(response.getUserId()) .username(StringUtils.isEmpty(response.getUserName()) ? response.getNickName() : response.getUserName()) .nickname(response.getNickName()) .avatar(response.getAvatar()) .location(location) .gender(AuthUserGender.getRealGender(response.getGender())) .token(authToken) .source(source.toString()) .build(); }
Example 3
Source File: AuthTeambitionRequest.java From JustAuth with MIT License | 5 votes |
@Override protected AuthUser getUserInfo(AuthToken authToken) { String accessToken = authToken.getAccessToken(); HttpHeader httpHeader = new HttpHeader(); httpHeader.add("Authorization", "OAuth2 " + accessToken); String response = new HttpUtils(config.getHttpConfig()).get(source.userInfo(), null, httpHeader, false); JSONObject object = JSONObject.parseObject(response); this.checkResponse(object); authToken.setUid(object.getString("_id")); return AuthUser.builder() .rawUserInfo(object) .uuid(object.getString("_id")) .username(object.getString("name")) .nickname(object.getString("name")) .avatar(object.getString("avatarUrl")) .blog(object.getString("website")) .location(object.getString("location")) .email(object.getString("email")) .gender(AuthUserGender.UNKNOWN) .token(authToken) .source(source.toString()) .build(); }
Example 4
Source File: AuthWeiboRequest.java From JustAuth with MIT License | 5 votes |
@Override protected AuthUser getUserInfo(AuthToken authToken) { String accessToken = authToken.getAccessToken(); String uid = authToken.getUid(); String oauthParam = String.format("uid=%s&access_token=%s", uid, accessToken); HttpHeader httpHeader = new HttpHeader(); httpHeader.add("Authorization", "OAuth2 " + oauthParam); httpHeader.add("API-RemoteIP", IpUtils.getLocalIp()); String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false); JSONObject object = JSONObject.parseObject(userInfo); if (object.containsKey("error")) { throw new AuthException(object.getString("error")); } return AuthUser.builder() .rawUserInfo(object) .uuid(object.getString("id")) .username(object.getString("name")) .avatar(object.getString("profile_image_url")) .blog(StringUtils.isEmpty(object.getString("url")) ? "https://weibo.com/" + object.getString("profile_url") : object .getString("url")) .nickname(object.getString("screen_name")) .location(object.getString("location")) .remark(object.getString("description")) .gender(AuthUserGender.getRealGender(object.getString("gender"))) .token(authToken) .source(source.toString()) .build(); }
Example 5
Source File: AuthLinkedinRequest.java From JustAuth with MIT License | 5 votes |
@Override protected AuthUser getUserInfo(AuthToken authToken) { String accessToken = authToken.getAccessToken(); HttpHeader httpHeader = new HttpHeader(); httpHeader.add("Host", "api.linkedin.com"); httpHeader.add("Connection", "Keep-Alive"); httpHeader.add("Authorization", "Bearer " + accessToken); String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false); JSONObject userInfoObject = JSONObject.parseObject(response); this.checkResponse(userInfoObject); String userName = getUserName(userInfoObject); // 获取用户头像 String avatar = this.getAvatar(userInfoObject); // 获取用户邮箱地址 String email = this.getUserEmail(accessToken); return AuthUser.builder() .rawUserInfo(userInfoObject) .uuid(userInfoObject.getString("id")) .username(userName) .nickname(userName) .avatar(avatar) .email(email) .token(authToken) .gender(AuthUserGender.UNKNOWN) .source(source.toString()) .build(); }
Example 6
Source File: AuthFeishuRequest.java From JustAuth with MIT License | 5 votes |
@Override protected AuthUser getUserInfo(AuthToken authToken) { String accessToken = authToken.getAccessToken(); String response = new HttpUtils(config.getHttpConfig()).get(source.userInfo(), null, new HttpHeader() .add("Content-Type", "application/json") .add("Authorization", "Bearer " + accessToken), false); JSONObject object = JSON.parseObject(response); return AuthUser.builder() .rawUserInfo(object) .avatar(object.getString("AvatarUrl")) .username(object.getString("Mobile")) .email(object.getString("Email")) .nickname("Name") .build(); }