| | |
| | | package org.dromara.common.social.topiam; |
| | | |
| | | import cn.hutool.core.codec.Base64; |
| | | import cn.hutool.core.lang.Dict; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import com.xkcoding.http.support.HttpHeader; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.zhyd.oauth.cache.AuthStateCache; |
| | |
| | | import org.dromara.common.core.utils.SpringUtils; |
| | | import org.dromara.common.json.utils.JsonUtils; |
| | | |
| | | import static org.dromara.common.social.topiam.AuthTopiamSource.TOPIAM; |
| | | import static org.dromara.common.social.topiam.AuthTopIamSource.TOPIAM; |
| | | |
| | | /** |
| | | * TopIAM 认证请求 |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected AuthToken getAccessToken(AuthCallback authCallback) { |
| | | public AuthToken getAccessToken(AuthCallback authCallback) { |
| | | String body = doPostAuthorizationCode(authCallback.getCode()); |
| | | Dict object = JsonUtils.parseMap(body); |
| | | checkResponse(object); |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected AuthUser getUserInfo(AuthToken authToken) { |
| | | public AuthUser getUserInfo(AuthToken authToken) { |
| | | String body = doGetUserInfo(authToken); |
| | | Dict object = JsonUtils.parseMap(body); |
| | | checkResponse(object); |
| | |
| | | .build(); |
| | | } |
| | | |
| | | @Override |
| | | protected String doPostAuthorizationCode(String code) { |
| | | HttpRequest request = HttpRequest.post(source.accessToken()) |
| | | .header("Authorization", "Basic " + Base64.encode("%s:%s".formatted(config.getClientId(), config.getClientSecret()))) |
| | | .form("grant_type", "authorization_code") |
| | | .form("code", code) |
| | | .form("redirect_uri", config.getRedirectUri()); |
| | | HttpResponse response = request.execute(); |
| | | return response.body(); |
| | | } |
| | | |
| | | @Override |
| | | protected String doGetUserInfo(AuthToken authToken) { |
| | |
| | | .build(); |
| | | } |
| | | |
| | | public static void checkResponse(Dict object) { |
| | | private static void checkResponse(Dict object) { |
| | | // oauth/token 验证异常 |
| | | if (object.containsKey("error")) { |
| | | throw new AuthException(object.getStr("error_description")); |