1
0
mirror of synced 2026-05-22 21:53:18 +00:00
Files
JustAuth/src/main/java/me/zhyd/oauth/request/AuthAliyunRequest.java
T

57 lines
1.9 KiB
Java
Raw Normal View History

2020-05-26 14:37:01 +08:00
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
import me.zhyd.oauth.enums.AuthUserGender;
2020-05-26 14:37:01 +08:00
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
/**
* 阿里云登录
*
* @author snippet0809 (https://github.com/snippet0809)
* @since 1.15.5
2020-05-26 14:37:01 +08:00
*/
public class AuthAliyunRequest extends AuthDefaultRequest {
public AuthAliyunRequest(AuthConfig config) {
super(config, AuthDefaultSource.ALIYUN);
}
public AuthAliyunRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthDefaultSource.ALIYUN, authStateCache);
}
@Override
public AuthToken getAccessToken(AuthCallback authCallback) {
2020-05-26 14:37:01 +08:00
String response = doPostAuthorizationCode(authCallback.getCode());
JSONObject accessTokenObject = JSONObject.parseObject(response);
return AuthToken.builder()
2021-03-13 23:15:22 +08:00
.accessToken(accessTokenObject.getString("access_token"))
.expireIn(accessTokenObject.getIntValue("expires_in"))
.tokenType(accessTokenObject.getString("token_type"))
.idToken(accessTokenObject.getString("id_token"))
.refreshToken(accessTokenObject.getString("refresh_token"))
.build();
2020-05-26 14:37:01 +08:00
}
@Override
public AuthUser getUserInfo(AuthToken authToken) {
2020-05-26 14:37:01 +08:00
String userInfo = doGetUserInfo(authToken);
JSONObject object = JSONObject.parseObject(userInfo);
return AuthUser.builder()
.rawUserInfo(object)
.uuid(object.getString("sub"))
.username(object.getString("login_name"))
.nickname(object.getString("name"))
.gender(AuthUserGender.UNKNOWN)
.token(authToken)
.source(source.toString())
.build();
2020-05-26 14:37:01 +08:00
}
}