mirror of
https://gitee.com/yadong.zhang/JustAuth.git
synced 2026-01-07 19:31:48 +08:00
Merge branch 'dev' into remove-urlbuilder
This commit is contained in:
commit
d5189aa30c
14
README.md
14
README.md
@ -37,10 +37,18 @@
|
||||
<td align="center" width="200"><a href="#授权google"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权facebook"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/facebook.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权抖音"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/douyin.png" width="20"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center" width="200"><a href="#授权领英"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/linkedin.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权微软"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/microsoft.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权小米"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/mi.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权今日头条"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/toutiao.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权Teambition"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/teambition.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权人人"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/renren.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权Pinterest"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/pinterest.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权Stack Overflow"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/stackoverflow.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权csdn"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
@ -120,6 +128,10 @@ authRequest.login(callback);
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/microsoft.png" width="20"> | [AuthMicrosoftRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java) | <a href="https://docs.microsoft.com/zh-cn/graph/auth/" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/mi.png" width="20"> | [AuthMiRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java) | <a href="https://dev.mi.com/console/doc/detail?pId=711" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/toutiao.png" width="20"> | [AuthToutiaoRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java) | <a href="https://open.mp.toutiao.com/#/resource?_k=y7mfgk" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/teambition.png" width="20"> | [AuthTeambitionRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java) | <a href="https://docs.teambition.com/" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/renren.png" width="20"> | [AuthRenrenRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java) | <a href="http://open.renren.com/wiki/OAuth2.0" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/pinterest.png" width="20"> | [AuthPinterestRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java) | <a href="https://developers.pinterest.com/docs/api/overview/?" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/stackoverflow.png" width="20"> | [AuthStackOverflowRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java) | <a href="https://api.stackexchange.com/docs" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"> | [AuthCsdnRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java) | 无 |
|
||||
|
||||
_请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经下线。如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了_
|
||||
@ -168,4 +180,4 @@ _请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经
|
||||
|
||||
| 支付宝 | 微信 |
|
||||
| :------------: | :------------: |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/qrcode/zfb_code.png" width="200"/> | <img src="https://gitee.com/yadong.zhang/static/raw/master/qrcode/wx_code.png" width="200" /> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/qrcode/zfb_code.png" width="200"/> | <img src="https://gitee.com/yadong.zhang/static/raw/master/qrcode/wx_code.png" width="200" /> |
|
||||
|
||||
@ -3,4 +3,5 @@
|
||||
- <img src="https://avatar.gitee.com/uploads/99/784199_yadong.zhang.png!avatar100?1462325358" width="20"> · yadong.zhang : <a href="https://github.com/zhangyd-c" target="_blank">[Github]</a> | <a href="https://gitee.com/yadong.zhang" target="_blank">[Gitee]</a> | <a href="https://www.zhyd.me" target="_blank">[个人网站]</a>
|
||||
- <img src="https://avatars0.githubusercontent.com/u/10429917?s=460&v=4" width="20"> · yangkai.shen : <a href="https://github.com/xkcoding" target="_blank">[Github]</a> | <a href="https://xkcoding.com" target="_blank">[个人网站]</a>
|
||||
- <img src="https://avatar.gitee.com/uploads/51/1651_dolphinboy.png!avatar100?1479346570" width="20"> · skqing : <a href="https://gitee.com/skqing" target="_blank">[Gitee]</a> | <a href="https://my.oschina.net/dolphinboy" target="_blank">[个人网站]</a>
|
||||
- <img src="https://avatars2.githubusercontent.com/u/2988765?s=115&v=4" width="20"> · pengisgood : <a href="https://github.com/pengisgood" target="_blank">[Github]</a> | <a href="https://pengisgood.github.io" target="_blank">[个人网站]</a>
|
||||
- 千年等一回,我只为等你...
|
||||
|
||||
18
example.md
18
example.md
@ -80,8 +80,24 @@ _注:非全部平台,部分平台可能不存在图例_
|
||||
|
||||
暂无
|
||||
|
||||
#### 授权Pinterest
|
||||
|
||||

|
||||
|
||||
#### 授权Renren
|
||||
|
||||

|
||||
|
||||
#### 授权Stack Overflow
|
||||
|
||||

|
||||
|
||||
#### 授权Twitter
|
||||
|
||||
暂无
|
||||
|
||||
#### 授权csdn
|
||||
|
||||
暂无
|
||||
|
||||
_请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经下线。如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了_
|
||||
_请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经下线。如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了_
|
||||
|
||||
7
pom.xml
7
pom.xml
@ -30,7 +30,7 @@
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>yadong.zhang</name>
|
||||
<name>Yadong.Zhang</name>
|
||||
<email>yadong.zhang0415@gmail.com</email>
|
||||
<url>https://www.zhyd.me</url>
|
||||
</developer>
|
||||
@ -39,6 +39,11 @@
|
||||
<email>shenyangkai1994@gmail.com</email>
|
||||
<url>https://xkcoding.com</url>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Hongwei.Peng</name>
|
||||
<email>pengisgood@gmail.com</email>
|
||||
<url>https://github.com/pengisgood</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
|
||||
@ -51,4 +51,11 @@ public class AuthConfig {
|
||||
* 1.8.0版本新增参数
|
||||
*/
|
||||
private String state;
|
||||
|
||||
/**
|
||||
* Stack Overflow Key
|
||||
* <p>
|
||||
* 1.9.0版本新增参数
|
||||
*/
|
||||
private String stackOverflowKey;
|
||||
}
|
||||
|
||||
@ -469,6 +469,46 @@ public enum AuthSource {
|
||||
public String userInfo() {
|
||||
return "https://api.renren.com/v2/user/get";
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Pinterest
|
||||
*/
|
||||
PINTEREST {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://api.pinterest.com/oauth";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://api.pinterest.com/v1/oauth/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://api.pinterest.com/v1/me";
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Stack Overflow
|
||||
*/
|
||||
STACK_OVERFLOW {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://stackoverflow.com/oauth";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://stackoverflow.com/oauth/access_token/json";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://api.stackexchange.com/2.2/me";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -139,7 +139,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl)
|
||||
.header("Host", "www.linkedin.com")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.execute();
|
||||
String accessTokenStr = response.body();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
|
||||
|
||||
@ -13,6 +13,8 @@ import me.zhyd.oauth.utils.UrlBuilder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static me.zhyd.oauth.utils.GlobalAuthUtil.parseQueryToMap;
|
||||
|
||||
/**
|
||||
* 微软登录
|
||||
*
|
||||
@ -37,12 +39,10 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
|
||||
* @return token对象
|
||||
*/
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
Map<String, Object> paramMap = new HashMap<>(6);
|
||||
HttpUtil.decodeParamMap(accessTokenUrl, "UTF-8").forEach(paramMap::put);
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl)
|
||||
.header("Host", "https://login.microsoftonline.com")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.form(paramMap)
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.form(parseQueryToMap(accessTokenUrl))
|
||||
.execute();
|
||||
String accessTokenStr = response.body();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
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.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.url.AuthPinterestUrlBuilder;
|
||||
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static me.zhyd.oauth.config.AuthSource.PINTEREST;
|
||||
|
||||
/**
|
||||
* Pinterest登录
|
||||
*
|
||||
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
|
||||
* @version 1.9.0
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public class AuthPinterestRequest extends AuthDefaultRequest {
|
||||
|
||||
public AuthPinterestRequest(AuthConfig config) {
|
||||
super(config, PINTEREST, new AuthPinterestUrlBuilder());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(authCallback.getCode());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
if (!response.isOk()) {
|
||||
throw new AuthException("Unable to get token from Pinterest using code [" + authCallback.getCode() + "]: " + accessTokenObject);
|
||||
}
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.tokenType(accessTokenObject.getString("token_type"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
|
||||
.accessToken(accessToken)
|
||||
.build())).execute();
|
||||
JSONObject userObj = JSONObject.parseObject(response.body()).getJSONObject("data");
|
||||
|
||||
return AuthUser.builder()
|
||||
.uuid(userObj.getString("id"))
|
||||
.avatar(getAvatarUrl(userObj))
|
||||
.username(userObj.getString("username"))
|
||||
.nickname(userObj.getString("first_name") + " " + userObj.getString("last_name"))
|
||||
.gender(AuthUserGender.UNKNOWN)
|
||||
.remark(userObj.getString("bio"))
|
||||
.token(authToken)
|
||||
.source(PINTEREST)
|
||||
.build();
|
||||
}
|
||||
|
||||
private String getAvatarUrl(JSONObject userObj) {
|
||||
// image is a map data structure
|
||||
JSONObject jsonObject = userObj.getJSONObject("image");
|
||||
if (Objects.isNull(jsonObject)) {
|
||||
return null;
|
||||
}
|
||||
return jsonObject.getJSONObject("60x60").getString("url");
|
||||
}
|
||||
|
||||
}
|
||||
@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
@ -14,6 +15,7 @@ import me.zhyd.oauth.utils.UrlBuilder;
|
||||
import java.util.Objects;
|
||||
|
||||
import static me.zhyd.oauth.config.AuthSource.RENREN;
|
||||
import static me.zhyd.oauth.model.AuthResponseStatus.SUCCESS;
|
||||
|
||||
/**
|
||||
* 人人登录
|
||||
@ -30,22 +32,14 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
if (!response.isOk()) {
|
||||
throw new AuthException("Unable to get token from renren using code [" + authCallback.getCode() + "]: " + accessTokenObject);
|
||||
}
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.refreshToken(accessTokenObject.getString("refresh_token"))
|
||||
.openId(accessTokenObject.getJSONObject("user").getString("id"))
|
||||
.build();
|
||||
return getToken(this.urlBuilder.getAccessTokenUrl(authCallback.getCode()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
|
||||
HttpResponse response = doGetUserInfo(authToken);
|
||||
|
||||
JSONObject userObj = JSONObject.parseObject(response.body()).getJSONObject("response");
|
||||
|
||||
return AuthUser.builder()
|
||||
@ -59,6 +53,30 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
return AuthResponse.builder()
|
||||
.code(SUCCESS.getCode())
|
||||
.data(getToken(this.urlBuilder.getRefreshUrl(authToken.getRefreshToken())))
|
||||
.build();
|
||||
}
|
||||
|
||||
private AuthToken getToken(String url) {
|
||||
HttpResponse response = HttpRequest.post(url).execute();
|
||||
JSONObject jsonObject = JSONObject.parseObject(response.body());
|
||||
if (!response.isOk()) {
|
||||
throw new AuthException("Failed to get token from Renren: " + jsonObject);
|
||||
}
|
||||
|
||||
return AuthToken.builder()
|
||||
.tokenType(jsonObject.getString("token_type"))
|
||||
.expireIn(jsonObject.getIntValue("expires_in"))
|
||||
.accessToken(jsonObject.getString("access_token"))
|
||||
.refreshToken(jsonObject.getString("refresh_token"))
|
||||
.openId(jsonObject.getJSONObject("user").getString("id"))
|
||||
.build();
|
||||
}
|
||||
|
||||
private String getAvatarUrl(JSONObject userObj) {
|
||||
JSONArray jsonArray = userObj.getJSONArray("avatar");
|
||||
if (Objects.isNull(jsonArray) || jsonArray.isEmpty()) {
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
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.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.url.AuthStackOverflowUrlBuilder;
|
||||
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
|
||||
|
||||
import static me.zhyd.oauth.config.AuthSource.STACK_OVERFLOW;
|
||||
import static me.zhyd.oauth.utils.GlobalAuthUtil.parseQueryToMap;
|
||||
|
||||
/**
|
||||
* Stack Overflow登录
|
||||
*
|
||||
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
|
||||
* @version 1.9.0
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public class AuthStackOverflowRequest extends AuthDefaultRequest {
|
||||
|
||||
public AuthStackOverflowRequest(AuthConfig config) {
|
||||
super(config, STACK_OVERFLOW, new AuthStackOverflowUrlBuilder());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(authCallback.getCode());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl)
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.form(parseQueryToMap(accessTokenUrl))
|
||||
.execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
if (!response.isOk()) {
|
||||
throw new AuthException("Unable to get token from Stack Overflow using code [" + authCallback.getCode() + "]: " + accessTokenObject);
|
||||
}
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.expireIn(accessTokenObject.getIntValue("expires"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
|
||||
.accessToken(accessToken)
|
||||
.build())).execute();
|
||||
JSONObject userObj = JSONObject.parseObject(response.body()).getJSONArray("items").getJSONObject(0);
|
||||
|
||||
return AuthUser.builder()
|
||||
.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(STACK_OVERFLOW)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
48
src/main/java/me/zhyd/oauth/url/AuthPinterestUrlBuilder.java
Normal file
48
src/main/java/me/zhyd/oauth/url/AuthPinterestUrlBuilder.java
Normal file
@ -0,0 +1,48 @@
|
||||
package me.zhyd.oauth.url;
|
||||
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthResponseStatus;
|
||||
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import static me.zhyd.oauth.config.AuthSource.PINTEREST;
|
||||
|
||||
/**
|
||||
* Pinterest相关的URL构建类
|
||||
*
|
||||
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
|
||||
* @version 1.9.0
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public class AuthPinterestUrlBuilder extends AuthDefaultUrlBuilder {
|
||||
|
||||
private static final String PINTEREST_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}";
|
||||
private static final String PINTEREST_USER_INFO_PATTERN = "{0}?access_token={1}&fields=id,username,first_name,last_name,bio,image";
|
||||
private static final String PINTEREST_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}&scope=read_public";
|
||||
|
||||
@Override
|
||||
public String getAccessTokenUrl(String code) {
|
||||
return MessageFormat.format(PINTEREST_ACCESS_TOKEN_PATTERN, PINTEREST.accessToken(), config.getClientId(), config.getClientSecret(), code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
|
||||
return MessageFormat.format(PINTEREST_USER_INFO_PATTERN, PINTEREST.userInfo(), userInfoEntity.getAccessToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl() {
|
||||
return MessageFormat.format(PINTEREST_AUTHORIZE_PATTERN, PINTEREST.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRefreshUrl(String refreshToken) {
|
||||
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRevokeUrl(String accessToken) {
|
||||
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package me.zhyd.oauth.url;
|
||||
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthResponseStatus;
|
||||
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import static me.zhyd.oauth.config.AuthSource.STACK_OVERFLOW;
|
||||
|
||||
/**
|
||||
* Stack Overflow相关的URL构建类
|
||||
*
|
||||
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
|
||||
* @version 1.9.0
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public class AuthStackOverflowUrlBuilder extends AuthDefaultUrlBuilder {
|
||||
|
||||
private static final String SO_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&redirect_uri={3}&code={4}";
|
||||
private static final String SO_USER_INFO_PATTERN = "{0}?access_token={1}&site=stackoverflow&key={2}";
|
||||
private static final String SO_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}";
|
||||
|
||||
@Override
|
||||
public String getAccessTokenUrl(String code) {
|
||||
return MessageFormat.format(SO_ACCESS_TOKEN_PATTERN, STACK_OVERFLOW.accessToken(), config.getClientId(), config.getClientSecret(), config.getRedirectUri(), code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
|
||||
return MessageFormat.format(SO_USER_INFO_PATTERN, STACK_OVERFLOW.userInfo(), userInfoEntity.getAccessToken(), config.getStackOverflowKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl() {
|
||||
return MessageFormat.format(SO_AUTHORIZE_PATTERN, STACK_OVERFLOW.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRefreshUrl(String refreshToken) {
|
||||
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRevokeUrl(String accessToken) {
|
||||
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ package me.zhyd.oauth.utils;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
@ -82,6 +83,7 @@ public class GlobalAuthUtil {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static String parseMapToString(Map<String, Object> params, boolean encode) {
|
||||
List<String> paramList = new ArrayList<>();
|
||||
params.forEach((k, v) -> {
|
||||
@ -94,6 +96,12 @@ public class GlobalAuthUtil {
|
||||
});
|
||||
return CollUtil.join(paramList, "&");
|
||||
}
|
||||
|
||||
public static Map<String, Object> parseQueryToMap(String url) {
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
HttpUtil.decodeParamMap(url, "UTF-8").forEach(paramMap::put);
|
||||
return paramMap;
|
||||
}
|
||||
|
||||
public static boolean isHttpProtocol(String url) {
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
|
||||
@ -1,3 +1,12 @@
|
||||
### 2019/07/18
|
||||
1. 合并github上[@pengisgood](https://github.com/pengisgood) 的[pr#19](https://github.com/zhangyd-c/JustAuth/pull/19),集成人人
|
||||
2. 合并github上[@pengisgood](https://github.com/pengisgood) 的[pr#20](https://github.com/zhangyd-c/JustAuth/pull/20),集成Pinterest
|
||||
2. 合并github上[@pengisgood](https://github.com/pengisgood) 的[pr#21](https://github.com/zhangyd-c/JustAuth/pull/21),集成StackOverflow
|
||||
|
||||
### 2019/07/17
|
||||
1. 优化代码
|
||||
2. 集成Teambition登录
|
||||
|
||||
### 2019/07/16
|
||||
1. 重构UrlBuilder类
|
||||
2. 将CSDN相关的类置为`Deprecated`,后续可能会删除,也可能一直保留。毕竟CSDN的openAPI已经不对外开放了。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user