me.zhyd.oauth.model.AuthToken Java Examples

The following examples show how to use me.zhyd.oauth.model.AuthToken. 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: AuthTeambitionRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
public AuthResponse refresh(AuthToken oldToken) {
    String uid = oldToken.getUid();
    String refreshToken = oldToken.getRefreshToken();

    Map<String, String> form = new HashMap<>(2);
    form.put("_userId", uid);
    form.put("refresh_token", refreshToken);
    String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
    JSONObject refreshTokenObject = JSONObject.parseObject(response);

    this.checkResponse(refreshTokenObject);

    return AuthResponse.builder()
        .code(AuthResponseStatus.SUCCESS.getCode())
        .data(AuthToken.builder()
            .accessToken(refreshTokenObject.getString("access_token"))
            .refreshToken(refreshTokenObject.getString("refresh_token"))
            .build())
        .build();
}
 
Example #2
Source File: AuthMeituanRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
    Map<String, String> form = new HashMap<>(4);
    form.put("app_id", config.getClientId());
    form.put("secret", config.getClientSecret());
    form.put("code", authCallback.getCode());
    form.put("grant_type", "authorization_code");

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

    this.checkResponse(object);

    return AuthToken.builder()
        .accessToken(object.getString("access_token"))
        .refreshToken(object.getString("refresh_token"))
        .expireIn(object.getIntValue("expires_in"))
        .build();
}
 
Example #3
Source File: AuthFeishuRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
public AuthResponse refresh(AuthToken authToken) {
    JSONObject requestObject = new JSONObject();
    requestObject.put("app_id", config.getClientId());
    requestObject.put("app_secret", config.getClientSecret());
    requestObject.put("grant_type", "refresh_token");
    requestObject.put("refresh_token", authToken.getRefreshToken());
    String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), requestObject.toJSONString(), new HttpHeader()
        .add("Content-Type", "application/json"));
    JSONObject jsonObject = JSON.parseObject(response);
    this.checkResponse(jsonObject);
    return AuthResponse.builder()
        .code(AuthResponseStatus.SUCCESS.getCode())
        .data(AuthToken.builder()
            .accessToken(jsonObject.getString("access_token"))
            .refreshToken(jsonObject.getString("refresh_token"))
            .expireIn(jsonObject.getIntValue("expires_in"))
            .tokenType(jsonObject.getString("token_type"))
            .openId(jsonObject.getString("open_id"))
            .build())
        .build();

}
 
Example #4
Source File: AuthJdRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
public AuthResponse refresh(AuthToken oldToken) {
    Map<String, String> params = new HashMap<>(5);
    params.put("app_key", config.getClientId());
    params.put("app_secret", config.getClientSecret());
    params.put("grant_type", "refresh_token");
    params.put("refresh_token", oldToken.getRefreshToken());
    String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), params, false);
    JSONObject object = JSONObject.parseObject(response);

    this.checkResponse(object);

    return AuthResponse.builder()
        .code(AuthResponseStatus.SUCCESS.getCode())
        .data(AuthToken.builder()
            .accessToken(object.getString("access_token"))
            .expireIn(object.getIntValue("expires_in"))
            .refreshToken(object.getString("refresh_token"))
            .scope(object.getString("scope"))
            .openId(object.getString("open_id"))
            .build())
        .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: AuthJdRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {

    Map<String, String> params = new HashMap<>(5);
    params.put("app_key", config.getClientId());
    params.put("app_secret", config.getClientSecret());
    params.put("grant_type", "authorization_code");
    params.put("code", authCallback.getCode());
    String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false);
    JSONObject object = JSONObject.parseObject(response);

    this.checkResponse(object);

    return AuthToken.builder()
        .accessToken(object.getString("access_token"))
        .expireIn(object.getIntValue("expires_in"))
        .refreshToken(object.getString("refresh_token"))
        .scope(object.getString("scope"))
        .openId(object.getString("open_id"))
        .build();
}
 
Example #7
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 #8
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 #9
Source File: AuthStackOverflowRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
    String accessTokenUrl = accessTokenUrl(authCallback.getCode());
    Map<String, String> form = MapUtil.parseStringToMap(accessTokenUrl, false);
    HttpHeader httpHeader = new HttpHeader();
    httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");
    String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false);

    JSONObject accessTokenObject = JSONObject.parseObject(response);
    this.checkResponse(accessTokenObject);

    return AuthToken.builder()
        .accessToken(accessTokenObject.getString("access_token"))
        .expireIn(accessTokenObject.getIntValue("expires"))
        .build();
}
 
Example #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: AuthLinkedinRequest.java    From JustAuth with MIT License 6 votes vote down vote up
/**
 * 获取token,适用于获取access_token和刷新token
 *
 * @param accessTokenUrl 实际请求token的地址
 * @return token对象
 */
private AuthToken getToken(String accessTokenUrl) {
    HttpHeader httpHeader = new HttpHeader();
    httpHeader.add("Host", "www.linkedin.com");
    httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");

    String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, null, httpHeader);
    JSONObject accessTokenObject = JSONObject.parseObject(response);

    this.checkResponse(accessTokenObject);

    return AuthToken.builder()
        .accessToken(accessTokenObject.getString("access_token"))
        .expireIn(accessTokenObject.getIntValue("expires_in"))
        .refreshToken(accessTokenObject.getString("refresh_token"))
        .build();
}
 
Example #16
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 #17
Source File: AuthElemeRequest.java    From JustAuth with MIT License 6 votes vote down vote up
@Override
public AuthResponse refresh(AuthToken oldToken) {
    Map<String, String> form = new HashMap<>(2);
    form.put("refresh_token", oldToken.getRefreshToken());
    form.put("grant_type", "refresh_token");

    HttpHeader httpHeader = this.buildHeader(CONTENT_TYPE_FORM, this.getRequestId(), true);
    String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, httpHeader, false);

    JSONObject object = JSONObject.parseObject(response);

    this.checkResponse(object);

    return AuthResponse.builder()
        .code(AuthResponseStatus.SUCCESS.getCode())
        .data(AuthToken.builder()
            .accessToken(object.getString("access_token"))
            .refreshToken(object.getString("refresh_token"))
            .tokenType(object.getString("token_type"))
            .expireIn(object.getIntValue("expires_in"))
            .build())
        .build();
}
 
Example #18
Source File: AuthMiRequest.java    From JustAuth with MIT License 6 votes vote down vote up
private AuthToken getToken(String accessTokenUrl) {
    String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
    String jsonStr = response.replace(PREFIX, Constants.EMPTY);
    JSONObject accessTokenObject = JSONObject.parseObject(jsonStr);

    if (accessTokenObject.containsKey("error")) {
        throw new AuthException(accessTokenObject.getString("error_description"));
    }

    return AuthToken.builder()
        .accessToken(accessTokenObject.getString("access_token"))
        .expireIn(accessTokenObject.getIntValue("expires_in"))
        .scope(accessTokenObject.getString("scope"))
        .tokenType(accessTokenObject.getString("token_type"))
        .refreshToken(accessTokenObject.getString("refresh_token"))
        .openId(accessTokenObject.getString("openId"))
        .macAlgorithm(accessTokenObject.getString("mac_algorithm"))
        .macKey(accessTokenObject.getString("mac_key"))
        .build();
}
 
Example #19
Source File: AuthMicrosoftRequest.java    From JustAuth with MIT License 6 votes vote down vote up
/**
 * 获取token,适用于获取access_token和刷新token
 *
 * @param accessTokenUrl 实际请求token的地址
 * @return token对象
 */
private AuthToken getToken(String accessTokenUrl) {
    HttpHeader httpHeader = new HttpHeader();

    Map<String, String> form = MapUtil.parseStringToMap(accessTokenUrl, false);

    String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false);
    JSONObject accessTokenObject = JSONObject.parseObject(response);

    this.checkResponse(accessTokenObject);

    return AuthToken.builder()
        .accessToken(accessTokenObject.getString("access_token"))
        .expireIn(accessTokenObject.getIntValue("expires_in"))
        .scope(accessTokenObject.getString("scope"))
        .tokenType(accessTokenObject.getString("token_type"))
        .refreshToken(accessTokenObject.getString("refresh_token"))
        .build();
}
 
Example #20
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 #21
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 #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: 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 #25
Source File: AuthWeChatEnterpriseRequest.java    From JustAuth with MIT License 5 votes vote down vote up
/**
 * 微信的特殊性,此时返回的信息同时包含 openid 和 access_token
 *
 * @param authCallback 回调返回的参数
 * @return 所有信息
 */
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
    String response = doGetAuthorizationCode(accessTokenUrl(authCallback.getCode()));

    JSONObject object = this.checkResponse(response);

    return AuthToken.builder()
        .accessToken(object.getString("access_token"))
        .expireIn(object.getIntValue("expires_in"))
        .code(authCallback.getCode())
        .build();
}
 
Example #26
Source File: AuthHuaweiRequest.java    From JustAuth with MIT License 5 votes vote down vote up
private AuthToken getAuthToken(String response) {
    JSONObject object = JSONObject.parseObject(response);

    this.checkResponse(object);

    return AuthToken.builder()
        .accessToken(object.getString("access_token"))
        .expireIn(object.getIntValue("expires_in"))
        .refreshToken(object.getString("refresh_token"))
        .build();
}
 
Example #27
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();
}
 
Example #28
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 #29
Source File: AuthHuaweiRequest.java    From JustAuth with MIT License 5 votes vote down vote up
/**
 * 返回获取userInfo的url
 *
 * @param authToken token
 * @return 返回获取userInfo的url
 */
@Override
protected String userInfoUrl(AuthToken authToken) {
    return UrlBuilder.fromBaseUrl(source.userInfo())
        .queryParam("nsp_ts", System.currentTimeMillis())
        .queryParam("access_token", authToken.getAccessToken())
        .queryParam("nsp_fmt", "JS")
        .queryParam("nsp_svc", "OpenUP.User.getInfo")
        .build();
}
 
Example #30
Source File: AuthPinterestRequest.java    From JustAuth with MIT License 5 votes vote down vote up
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
    String response = doPostAuthorizationCode(authCallback.getCode());
    JSONObject accessTokenObject = JSONObject.parseObject(response);
    this.checkResponse(accessTokenObject);
    return AuthToken.builder()
        .accessToken(accessTokenObject.getString("access_token"))
        .tokenType(accessTokenObject.getString("token_type"))
        .build();
}