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

🔀 合并github中的pr

This commit is contained in:
yadong.zhang
2019-06-20 10:10:18 +08:00
parent cf74f811fa
commit 2f88c23405
51 changed files with 381 additions and 824 deletions
@@ -4,8 +4,8 @@ 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.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
@@ -29,15 +29,14 @@ public class AuthGithubRequest extends BaseAuthRequest {
@Override
protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
Map<String, String> res = GlobalAuthUtil.parseStringToMap(response.body());
if (res.containsKey("error")) {
throw new AuthException(res.get("error") + ":" + res.get("error_description"));
}
return AuthToken.builder()
.accessToken(res.get("access_token"))
.build();
return AuthToken.builder().accessToken(res.get("access_token")).build();
}
@Override
@@ -61,4 +60,14 @@ public class AuthGithubRequest extends BaseAuthRequest {
.source(AuthSource.GITHUB)
.build();
}
/**
* 返回认证url,可自行跳转页面
*
* @return 返回授权地址
*/
@Override
public String authorize() {
return UrlBuilder.getGithubAuthorizeUrl(config.getClientId(), config.getRedirectUri());
}
}