me.zhyd.oauth.model.AuthUser Java Examples

The following examples show how to use me.zhyd.oauth.model.AuthUser. 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: AuthStackOverflowRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String userInfoUrl = UrlBuilder.fromBaseUrl(this.source.userInfo())
        .queryParam("access_token", authToken.getAccessToken())
        .queryParam("site", "stackoverflow")
        .queryParam("key", this.config.getStackOverflowKey())
        .build();
    String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl);
    JSONObject object = JSONObject.parseObject(response);
    this.checkResponse(object);
    JSONObject userObj = object.getJSONArray("items").getJSONObject(0);

    return AuthUser.builder()
        .rawUserInfo(userObj)
        .uuid(userObj.getString("user_id"))
        .avatar(userObj.getString("profile_image"))
        .location(userObj.getString("location"))
        .nickname(userObj.getString("display_name"))
        .blog(userObj.getString("website_url"))
        .gender(AuthUserGender.UNKNOWN)
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #2
Source File: AuthGitlabRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String response = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(response);

    this.checkResponse(object);

    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("id"))
        .username(object.getString("username"))
        .nickname(object.getString("name"))
        .avatar(object.getString("avatar_url"))
        .blog(object.getString("web_url"))
        .company(object.getString("organization"))
        .location(object.getString("location"))
        .email(object.getString("email"))
        .remark(object.getString("bio"))
        .gender(AuthUserGender.UNKNOWN)
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #3
Source File: AuthGoogleRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    HttpHeader httpHeader = new HttpHeader();
    httpHeader.add("Authorization", "Bearer " + authToken.getAccessToken());
    String userInfo = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, httpHeader);
    JSONObject object = JSONObject.parseObject(userInfo);
    this.checkResponse(object);
    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("sub"))
        .username(object.getString("email"))
        .avatar(object.getString("picture"))
        .nickname(object.getString("name"))
        .location(object.getString("locale"))
        .email(object.getString("email"))
        .gender(AuthUserGender.UNKNOWN)
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #4
Source File: AuthCodingRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String response = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(response);
    this.checkResponse(object);

    object = object.getJSONObject("data");
    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("id"))
        .username(object.getString("name"))
        .avatar("https://coding.net" + object.getString("avatar"))
        .blog("https://coding.net" + object.getString("path"))
        .nickname(object.getString("name"))
        .company(object.getString("company"))
        .location(object.getString("location"))
        .gender(AuthUserGender.getRealGender(object.getString("sex")))
        .email(object.getString("email"))
        .remark(object.getString("slogan"))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #5
Source File: AuthWeChatEnterpriseRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String response = doGetUserInfo(authToken);
    JSONObject object = this.checkResponse(response);

    // 返回 OpenId 或其他,均代表非当前企业用户,不支持
    if (!object.containsKey("UserId")) {
        throw new AuthException(AuthResponseStatus.UNIDENTIFIED_PLATFORM, source);
    }
    String userId = object.getString("UserId");
    String userDetailResponse = getUserDetail(authToken.getAccessToken(), userId);
    JSONObject userDetail = this.checkResponse(userDetailResponse);

    return AuthUser.builder()
        .rawUserInfo(userDetail)
        .username(userDetail.getString("name"))
        .nickname(userDetail.getString("alias"))
        .avatar(userDetail.getString("avatar"))
        .location(userDetail.getString("address"))
        .email(userDetail.getString("email"))
        .uuid(userId)
        .gender(AuthUserGender.getWechatRealGender(userDetail.getString("gender")))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #6
Source File: AuthPinterestRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String userinfoUrl = userInfoUrl(authToken);
    // TODO: 是否需要 .setFollowRedirects(true)
    String response = new HttpUtils(config.getHttpConfig()).get(userinfoUrl);
    JSONObject object = JSONObject.parseObject(response);
    this.checkResponse(object);
    JSONObject userObj = object.getJSONObject("data");
    return AuthUser.builder()
        .rawUserInfo(userObj)
        .uuid(userObj.getString("id"))
        .avatar(getAvatarUrl(userObj))
        .username(userObj.getString("username"))
        .nickname(userObj.getString("first_name") + " " + userObj.getString("last_name"))
        .gender(AuthUserGender.UNKNOWN)
        .remark(userObj.getString("bio"))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #7
Source File: AuthGiteeRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String userInfo = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(userInfo);
    this.checkResponse(object);
    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("id"))
        .username(object.getString("login"))
        .avatar(object.getString("avatar_url"))
        .blog(object.getString("blog"))
        .nickname(object.getString("name"))
        .company(object.getString("company"))
        .location(object.getString("address"))
        .email(object.getString("email"))
        .remark(object.getString("bio"))
        .gender(AuthUserGender.UNKNOWN)
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #8
Source File: AuthQqRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String openId = this.getOpenId(authToken);
    String response = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(response);
    if (object.getIntValue("ret") != 0) {
        throw new AuthException(object.getString("msg"));
    }
    String avatar = object.getString("figureurl_qq_2");
    if (StringUtils.isEmpty(avatar)) {
        avatar = object.getString("figureurl_qq_1");
    }

    String location = String.format("%s-%s", object.getString("province"), object.getString("city"));
    return AuthUser.builder()
        .rawUserInfo(object)
        .username(object.getString("nickname"))
        .nickname(object.getString("nickname"))
        .avatar(avatar)
        .location(location)
        .uuid(openId)
        .gender(AuthUserGender.getRealGender(object.getString("gender")))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #9
Source File: AuthMicrosoftRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@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 #10
Source File: AuthOschinaRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String response = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(response);
    this.checkResponse(object);
    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("id"))
        .username(object.getString("name"))
        .nickname(object.getString("name"))
        .avatar(object.getString("avatar"))
        .blog(object.getString("url"))
        .location(object.getString("location"))
        .gender(AuthUserGender.getRealGender(object.getString("gender")))
        .email(object.getString("email"))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #11
Source File: AuthRenrenRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String response = doGetUserInfo(authToken);
    JSONObject userObj = JSONObject.parseObject(response).getJSONObject("response");

    return AuthUser.builder()
        .rawUserInfo(userObj)
        .uuid(userObj.getString("id"))
        .avatar(getAvatarUrl(userObj))
        .nickname(userObj.getString("name"))
        .company(getCompany(userObj))
        .gender(getGender(userObj))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #12
Source File: AuthDouyinRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String response = doGetUserInfo(authToken);
    JSONObject userInfoObject = JSONObject.parseObject(response);
    this.checkResponse(userInfoObject);
    JSONObject object = userInfoObject.getJSONObject("data");
    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("union_id"))
        .username(object.getString("nickname"))
        .nickname(object.getString("nickname"))
        .avatar(object.getString("avatar"))
        .remark(object.getString("description"))
        .gender(AuthUserGender.getRealGender(object.getString("gender")))
        .location(String.format("%s %s %s", object.getString("country"), object.getString("province"), object.getString("city")))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #13
Source File: AuthGithubRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String response = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(response);

    this.checkResponse(object.containsKey("error"), object.getString("error_description"));

    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("id"))
        .username(object.getString("login"))
        .avatar(object.getString("avatar_url"))
        .blog(object.getString("blog"))
        .nickname(object.getString("name"))
        .company(object.getString("company"))
        .location(object.getString("location"))
        .email(object.getString("email"))
        .remark(object.getString("bio"))
        .gender(AuthUserGender.UNKNOWN)
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #14
Source File: AuthTaobaoRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String response = doPostAuthorizationCode(authToken.getAccessCode());
    JSONObject accessTokenObject = JSONObject.parseObject(response);
    if (accessTokenObject.containsKey("error")) {
        throw new AuthException(accessTokenObject.getString("error_description"));
    }
    authToken.setAccessToken(accessTokenObject.getString("access_token"));
    authToken.setRefreshToken(accessTokenObject.getString("refresh_token"));
    authToken.setExpireIn(accessTokenObject.getIntValue("expires_in"));
    authToken.setUid(accessTokenObject.getString("taobao_user_id"));
    authToken.setOpenId(accessTokenObject.getString("taobao_open_uid"));

    String nick = GlobalAuthUtils.urlDecode(accessTokenObject.getString("taobao_user_nick"));
    return AuthUser.builder()
        .rawUserInfo(new JSONObject())
        .uuid(accessTokenObject.getString("taobao_user_id"))
        .username(nick)
        .nickname(nick)
        .gender(AuthUserGender.UNKNOWN)
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #15
Source File: AuthToutiaoRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String userResponse = doGetUserInfo(authToken);

    JSONObject userProfile = JSONObject.parseObject(userResponse);

    this.checkResponse(userProfile);

    JSONObject user = userProfile.getJSONObject("data");

    boolean isAnonymousUser = user.getIntValue("uid_type") == 14;
    String anonymousUserName = "匿名用户";

    return AuthUser.builder()
        .rawUserInfo(user)
        .uuid(user.getString("uid"))
        .username(isAnonymousUser ? anonymousUserName : user.getString("screen_name"))
        .nickname(isAnonymousUser ? anonymousUserName : user.getString("screen_name"))
        .avatar(user.getString("avatar_url"))
        .remark(user.getString("description"))
        .gender(AuthUserGender.getRealGender(user.getString("gender")))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #16
Source File: AuthMeituanRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    Map<String, String> form = new HashMap<>(3);
    form.put("app_id", config.getClientId());
    form.put("secret", config.getClientSecret());
    form.put("access_token", authToken.getAccessToken());

    String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false);
    JSONObject object = JSONObject.parseObject(response);

    this.checkResponse(object);

    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("openid"))
        .username(object.getString("nickname"))
        .nickname(object.getString("nickname"))
        .avatar(object.getString("avatar"))
        .gender(AuthUserGender.UNKNOWN)
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #17
Source File: SocialSignOnProviderService.java    From MaxKey with Apache License 2.0 6 votes vote down vote up
public String getAccountId(String provider,AuthResponse<?> authResponse) {
	if(provider.equalsIgnoreCase("WeChatOpen")) {
		return ((AuthUser)authResponse.getData()).getUuid();
	}else if(provider.equalsIgnoreCase("sinaweibo")) {
		return ((AuthUser)authResponse.getData()).getUuid();
	}else if(provider.equalsIgnoreCase("qq")) {
		return ((AuthUser)authResponse.getData()).getUuid();
	}else if(provider.equalsIgnoreCase("Alipay")) {
		return ((AuthUser)authResponse.getData()).getUuid();
	}else if(provider.equalsIgnoreCase("Twitter")) {
		return ((AuthUser)authResponse.getData()).getUuid();
	}else if(provider.equalsIgnoreCase("google")) {
		return ((AuthUser)authResponse.getData()).getUuid();
	}else if(provider.equalsIgnoreCase("microsoft")) {
		return ((AuthUser)authResponse.getData()).getUuid();
	}else if(provider.equalsIgnoreCase("Linkedin")) {
		return ((AuthUser)authResponse.getData()).getUuid();
	}else if(provider.equalsIgnoreCase("DingTalk")) {
		return ((AuthUser)authResponse.getData()).getUuid();
	}else {
	    return ((AuthUser)authResponse.getData()).getUuid();
	}
}
 
Example #18
Source File: AuthServiceImpl.java    From OneBlog with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean login(String source, AuthCallback callback) {
    AuthRequest authRequest = RequestFactory.getInstance(source).getRequest();
    AuthResponse response = authRequest.login(callback);
    if (response.ok()) {
        AuthUser authUser = (AuthUser) response.getData();
        User newUser = BeanConvertUtil.doConvert(authUser, User.class);
        newUser.setSource(authUser.getSource().toString());
        if (null != authUser.getGender()) {
            newUser.setGender(authUser.getGender().getCode());
        }
        User user = userService.getByUuidAndSource(authUser.getUuid(), authUser.getSource().toString());
        newUser.setUserType(UserTypeEnum.USER);
        if (null != user) {
            newUser.setId(user.getId());
            userService.updateSelective(newUser);
        } else {
            userService.insert(newUser);
        }
        SessionUtil.setUser(newUser);
        return true;
    }
    log.warn("[{}] {}", source, response.getMsg());
    return false;
}
 
Example #19
Source File: AuthExtendRequestTest.java    From JustAuth with MIT License 6 votes vote down vote up
@Test
public void login() {
    AuthRequest request = new AuthExtendRequest(AuthConfig.builder()
        .clientId("clientId")
        .clientSecret("clientSecret")
        .redirectUri("http://redirectUri")
        .build());

    String state = AuthStateUtils.createState();
    request.authorize(state);
    AuthCallback callback = AuthCallback.builder()
        .code("code")
        .state(state)
        .build();
    AuthResponse response = request.login(callback);
    Assert.assertNotNull(response);

    AuthUser user = (AuthUser) response.getData();
    Assert.assertNotNull(user);
    System.out.println(JSON.toJSONString(user));
}
 
Example #20
Source File: SocialLoginServiceImpl.java    From FEBS-Cloud with Apache License 2.0 6 votes vote down vote up
@Override
public FebsResponse resolveLogin(String oauthType, AuthCallback callback) throws FebsException {
    FebsResponse febsResponse = new FebsResponse();
    AuthRequest authRequest = factory.get(getAuthSource(oauthType));
    AuthResponse<?> response = authRequest.login(resolveAuthCallback(callback));
    if (response.ok()) {
        AuthUser authUser = (AuthUser) response.getData();
        UserConnection userConnection = userConnectionService.selectByCondition(authUser.getSource().toString(), authUser.getUuid());
        if (userConnection == null) {
            febsResponse.message(NOT_BIND).data(authUser);
        } else {
            SystemUser user = userManager.findByName(userConnection.getUserName());
            if (user == null) {
                throw new FebsException("系统中未找到与第三方账号对应的账户");
            }
            OAuth2AccessToken oAuth2AccessToken = getOauth2AccessToken(user);
            febsResponse.message(SOCIAL_LOGIN_SUCCESS).data(oAuth2AccessToken);
            febsResponse.put(USERNAME, user.getUsername());
        }
    } else {
        throw new FebsException(String.format("第三方登录失败,%s", response.getMsg()));
    }
    return febsResponse;
}
 
Example #21
Source File: AuthCsdnRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String response = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(response);
    this.checkResponse(object);
    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("username"))
        .username(object.getString("username"))
        .remark(object.getString("description"))
        .blog(object.getString("website"))
        .gender(AuthUserGender.UNKNOWN)
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #22
Source File: AuthFacebookRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String userInfo = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(userInfo);
    this.checkResponse(object);
    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("id"))
        .username(object.getString("name"))
        .nickname(object.getString("name"))
        .blog(object.getString("link"))
        .avatar(getUserPicture(object))
        .location(object.getString("locale"))
        .email(object.getString("email"))
        .gender(AuthUserGender.getRealGender(object.getString("gender")))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #23
Source File: AuthDingTalkRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String code = authToken.getAccessCode();
    JSONObject param = new JSONObject();
    param.put("tmp_auth_code", code);
    String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), param.toJSONString());
    JSONObject object = JSON.parseObject(response);
    if (object.getIntValue("errcode") != 0) {
        throw new AuthException(object.getString("errmsg"));
    }
    object = object.getJSONObject("user_info");
    AuthToken token = AuthToken.builder()
        .openId(object.getString("openid"))
        .unionId(object.getString("unionid"))
        .build();
    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.getString("unionid"))
        .nickname(object.getString("nick"))
        .username(object.getString("nick"))
        .gender(AuthUserGender.UNKNOWN)
        .source(source.toString())
        .token(token)
        .build();
}
 
Example #24
Source File: AuthKujialeRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
public AuthUser getUserInfo(AuthToken authToken) {
    String openId = this.getOpenId(authToken);
    String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl(source.userInfo())
        .queryParam("access_token", authToken.getAccessToken())
        .queryParam("open_id", openId)
        .build());
    JSONObject object = JSONObject.parseObject(response);
    if (!"0".equals(object.getString("c"))) {
        throw new AuthException(object.getString("m"));
    }
    JSONObject resultObject = object.getJSONObject("d");

    return AuthUser.builder()
        .rawUserInfo(resultObject)
        .username(resultObject.getString("userName"))
        .nickname(resultObject.getString("userName"))
        .avatar(resultObject.getString("avatar"))
        .uuid(resultObject.getString("openId"))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #25
Source File: AuthBaiduRequest.java    From JustAuth with MIT License 6 votes vote down vote up
/**
 * https://openapi.baidu.com/rest/2.0/passport/users/getInfo?access_token=121.c86e87cc0828cc1dabb8faee540531d4.YsUIAWvYbgqVni1VhkgKgyLh8nEyELbDOEZs_OA.OgDgmA
 * https://openapi.baidu.com/rest/2.0/passport/users/getInfo?access_token=121.2907d9facf9fb97adf7287fa75496eda.Y3NSjR3-3HKt1RgT0HEl7GgxRXT5gOOVdngXezY.OcC_7g
 * 新旧应用返回的用户信息不一致
 * @param authToken token信息
 * @return AuthUser
 */
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String userInfo = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(userInfo);
    this.checkResponse(object);
    return AuthUser.builder()
        .rawUserInfo(object)
        .uuid(object.containsKey("userid") ? object.getString("userid") : object.getString("openid"))
        .username(object.getString("username"))
        .nickname(object.getString("username"))
        .avatar(getAvatar(object))
        .remark(object.getString("userdetail"))
        .gender(AuthUserGender.getRealGender(object.getString("sex")))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #26
Source File: AuthLinkedinRequest.java    From JustAuth with MIT License 5 votes vote down vote up
@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 #27
Source File: AuthMiRequest.java    From JustAuth with MIT License 5 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    // 获取用户信息
    String userResponse = doGetUserInfo(authToken);

    JSONObject userProfile = JSONObject.parseObject(userResponse);
    if ("error".equalsIgnoreCase(userProfile.getString("result"))) {
        throw new AuthException(userProfile.getString("description"));
    }

    JSONObject object = userProfile.getJSONObject("data");

    AuthUser authUser = AuthUser.builder()
        .rawUserInfo(object)
        .uuid(authToken.getOpenId())
        .username(object.getString("miliaoNick"))
        .nickname(object.getString("miliaoNick"))
        .avatar(object.getString("miliaoIcon"))
        .email(object.getString("mail"))
        .gender(AuthUserGender.UNKNOWN)
        .token(authToken)
        .source(source.toString())
        .build();

    // 获取用户邮箱手机号等信息
    String emailPhoneUrl = MessageFormat.format("{0}?clientId={1}&token={2}", "https://open.account.xiaomi.com/user/phoneAndEmail", config
        .getClientId(), authToken.getAccessToken());

    String emailResponse = new HttpUtils(config.getHttpConfig()).get(emailPhoneUrl);
    JSONObject userEmailPhone = JSONObject.parseObject(emailResponse);
    if (!"error".equalsIgnoreCase(userEmailPhone.getString("result"))) {
        JSONObject emailPhone = userEmailPhone.getJSONObject("data");
        authUser.setEmail(emailPhone.getString("email"));
    } else {
        Log.warn("小米开发平台暂时不对外开放用户手机及邮箱信息的获取");
    }

    return authUser;
}
 
Example #28
Source File: AuthFeishuRequest.java    From JustAuth with MIT License 5 votes vote down vote up
@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();
}
 
Example #29
Source File: AuthWeChatOpenRequest.java    From JustAuth with MIT License 5 votes vote down vote up
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    String openId = authToken.getOpenId();

    String response = doGetUserInfo(authToken);
    JSONObject object = JSONObject.parseObject(response);

    this.checkResponse(object);

    String location = String.format("%s-%s-%s", object.getString("country"), object.getString("province"), object.getString("city"));

    if (object.containsKey("unionid")) {
        authToken.setUnionId(object.getString("unionid"));
    }

    return AuthUser.builder()
        .rawUserInfo(object)
        .username(object.getString("nickname"))
        .nickname(object.getString("nickname"))
        .avatar(object.getString("headimgurl"))
        .location(location)
        .uuid(openId)
        .gender(AuthUserGender.getWechatRealGender(object.getString("sex")))
        .token(authToken)
        .source(source.toString())
        .build();
}
 
Example #30
Source File: AuthExtendRequest.java    From JustAuth with MIT License 5 votes vote down vote up
/**
 * 使用token换取用户信息
 *
 * @param authToken token信息
 * @return 用户信息
 * @see AuthDefaultRequest#getAccessToken(AuthCallback)
 */
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
    return AuthUser.builder()
        .username("test")
        .nickname("test")
        .gender(AuthUserGender.MALE)
        .token(authToken)
        .source(this.source.toString())
        .build();
}