1
0
mirror of synced 2026-05-22 21:53:18 +00:00

👌 更新代码

This commit is contained in:
yadong.zhang
2019-02-21 13:43:16 +08:00
parent e6e016b0dd
commit ea1aa53ab0
4 changed files with 46 additions and 18 deletions
@@ -4,10 +4,14 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.GlobalAuthUtil;
import me.zhyd.oauth.utils.UrlBuilder;
import java.util.Map;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
@@ -25,8 +29,11 @@ public class AuthGithubRequest extends BaseAuthRequest {
protected String getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
String accessTokenStr = response.body();
return accessTokenStr.split("&")[0];
Map<String, String> res = GlobalAuthUtil.parseStringToMap(response.body());
if (res.containsKey("error")) {
throw new AuthException(res.get("error") + ":" + res.get("error_description"));
}
return res.get("access_token");
}
@Override