Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 278a435cdb | |||
| 28466f8ab5 | |||
| c6bd5d9e5d |
+3
-3
@@ -6,7 +6,7 @@
|
||||
</p>
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://search.maven.org/search?q=JustAuth">
|
||||
<img src="https://img.shields.io/badge/Maven%20Central--1.15.2-alpha-blue" ></img>
|
||||
<img src="https://img.shields.io/badge/Maven%20Central--1.15.4-alpha-blue" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
|
||||
@@ -15,7 +15,7 @@
|
||||
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/" title="API文档">
|
||||
<img src="https://img.shields.io/badge/Api%20Docs--1.15.2-alpha-latest-orange" ></img>
|
||||
<img src="https://img.shields.io/badge/Api%20Docs--1.15.4-alpha-latest-orange" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://docs.justauth.whnb.wang" title="参考文档">
|
||||
<img src="https://img.shields.io/badge/Docs-latest-blueviolet.svg" ></img>
|
||||
@@ -97,7 +97,7 @@ These artifacts are available from Maven Central:
|
||||
<dependency>
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.15.2-alpha</version>
|
||||
<version>1.15.4-alpha</version>
|
||||
</dependency>
|
||||
```
|
||||
- Using JustAuth
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</p>
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://search.maven.org/search?q=JustAuth">
|
||||
<img src="https://img.shields.io/badge/Maven%20Central--1.15.2-alpha-blue" ></img>
|
||||
<img src="https://img.shields.io/badge/Maven%20Central--1.15.4-alpha-blue" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
|
||||
@@ -15,7 +15,7 @@
|
||||
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/" title="API文档">
|
||||
<img src="https://img.shields.io/badge/Api%20Docs--1.15.2-alpha-latest-orange" ></img>
|
||||
<img src="https://img.shields.io/badge/Api%20Docs--1.15.4-alpha-latest-orange" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://docs.justauth.whnb.wang" title="参考文档">
|
||||
<img src="https://img.shields.io/badge/Docs-latest-blueviolet.svg" ></img>
|
||||
@@ -96,7 +96,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
|
||||
<dependency>
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.15.2-alpha</version>
|
||||
<version>1.15.4-alpha</version>
|
||||
</dependency>
|
||||
```
|
||||
- 调用api
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.15.2-alpha
|
||||
1.15.4-alpha
|
||||
|
||||
+11
@@ -150,4 +150,15 @@ AuthRequest authRequest = new AuthQqRequest(AuthConfig.builder()
|
||||
|
||||
ps: 我要去祭天了
|
||||
|
||||
## 13. 为什么集成国外平台时,一直提示 `connect time out`?
|
||||
|
||||
所有国外平台都无法直接通过java进行访问API,目前[simple-http](https://github.com/xkcoding/simple-http) Release版本,暂不支持添加代理,所以目前需要手动开启代理。
|
||||
|
||||
代理开启的方式:
|
||||
```java
|
||||
System.setProperty("proxyPort", "10080");
|
||||
System.setProperty("proxyHost", "127.0.0.1");
|
||||
```
|
||||
以上代码可以在声明 `AuthRequest` 时创建,也可以全局执行。
|
||||
|
||||
本地如果支持科学上网,就用自己本地的代理端口即可,如果不支持科学上网,可以去网上找一些免费的代理IP进行测试(请自行操作)。
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@
|
||||
</p>
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://search.maven.org/search?q=JustAuth">
|
||||
<img src="https://img.shields.io/badge/Maven%20Central--1.15.2-alpha-blue" ></img>
|
||||
<img src="https://img.shields.io/badge/Maven%20Central--1.15.4-alpha-blue" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
|
||||
@@ -18,7 +18,7 @@
|
||||
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/" title="API文档">
|
||||
<img src="https://img.shields.io/badge/Api%20Docs--1.15.2-alpha-latest-orange" ></img>
|
||||
<img src="https://img.shields.io/badge/Api%20Docs--1.15.4-alpha-latest-orange" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://docs.justauth.whnb.wang" title="参考文档">
|
||||
<img src="https://img.shields.io/badge/Docs-latest-blueviolet.svg" ></img>
|
||||
|
||||
+5
-2
@@ -1,8 +1,8 @@
|
||||
# :alien: 404:alien:
|
||||
|
||||
**非常感谢您对JustAuth的关注**,您现在查询的内容,作者正在补充中!
|
||||
**非常感谢您对JustAuth的关注**,您现在查询的内容,作者**正在补充**中!
|
||||
|
||||
您可能对以下文章感兴趣:
|
||||
### 您可能对以下文章感兴趣:
|
||||
|
||||
- [OAuth的授权流程是什么样的?](https://docs.justauth.whnb.wang/#/oauth)
|
||||
- [如何使用JustAuth?](https://docs.justauth.whnb.wang/#/how-to-use)
|
||||
@@ -25,6 +25,9 @@
|
||||
- [酷家乐登录](oauth/kujiale.md)
|
||||
- 更多文章,正在补充中...
|
||||
|
||||
### 其他资料
|
||||
|
||||
- [参考文档](references.md)
|
||||
|
||||
### 如果还是没有您想要的内容,您可以:
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
|
||||

|
||||
# JustAuth <small>1.15.2-alpha</small>
|
||||
# JustAuth <small>1.15.4-alpha</small>
|
||||
|
||||
<strong>史上最全的整合第三方登录的开源库</strong>
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
- [√ 微博登录](oauth/weibo.md)
|
||||
- [√ 支付宝登录](oauth/alipay.md)
|
||||
- [√ 酷家乐登录](oauth/kujiale.md)
|
||||
- [√ 推特登录](oauth/twitter.md)
|
||||
- [CSDN登录](oauth/csdn.md)
|
||||
- [微信企业版登录](oauth/wechatEnterprise.md)
|
||||
- [微信公众平台登录](oauth/wechat_mp.md)
|
||||
@@ -46,4 +47,5 @@
|
||||
- [JustAuth与现有用户系统整合](extended/justauth_integrated_with_the_existing_account_system.md)
|
||||
- [Who is using](users.md)
|
||||
- [致谢](thx.md)
|
||||
- [参考文档](references.md)
|
||||
- [更新记录](update.md)
|
||||
|
||||
@@ -19,6 +19,13 @@
|
||||
- `stackOverflowKey` Stack Overflow 登陆时需单独提供的key,由**第三方平台颁发**
|
||||
- `agentId` 企业微信登陆时需单独提供该值,由**第三方平台颁发**,为授权方的网页应用ID
|
||||
- `source` JustAuth支持的第三方平台,比如:GITHUB、GITEE等
|
||||
- `uuid` 一般为第三方平台的用户ID。以下几个平台需特别注意:
|
||||
- 钉钉、抖音:`uuid` 为用户的 `unionid`
|
||||
- 微信公众平台登录、京东、酷家乐、美团:`uuid` 为用户的 `openId`
|
||||
- 微信开放平台登录、QQ:`uuid` 为用户的 `openId`,平台支持获取`unionid`, `unionid` 在 `AuthToken` 中(如果支持),在登录完成后,可以通过 `response.getData().getToken().getUnionId()` 获取
|
||||
- Google:`uuid` 为用户的 `sub`,`sub`为Google的所有账户体系中用户唯一的身份标识符,详见:[OpenID Connect](https://developers.google.com/identity/protocols/oauth2/openid-connect)
|
||||
|
||||
注:建议通过`uuid` + `source`的方式唯一确定一个用户,这样可以解决用户身份归属的问题。因为 单个用户ID 在某一平台中是唯一的,但不能保证在所有平台中都是唯一的。
|
||||
|
||||
## 参考资料
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
## 1. 申请应用
|
||||
|
||||
参考文章:[twitter三方登录的实现](https://my.oschina.net/u/3361217/blog/1438877),只需关注创建应用部分即可。
|
||||
|
||||
copy以下三个信息:`App ID`、`App Key`和`网站回调域`。
|
||||
|
||||
> 友情提示:twitter现不支持个人用户创建应用
|
||||
|
||||
## 2. 集成JustAuth
|
||||
|
||||
|
||||
### 2.1 引入依赖
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>${latest.version}</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
`${latest.version}`表示当前最新的版本,可以在[这儿](https://github.com/justauth/JustAuth/releases)获取最新的版本信息。
|
||||
|
||||
### 2.2 创建Request
|
||||
|
||||
```java
|
||||
// 国外平台 目前必须要手动配置代理
|
||||
System.setProperty("proxyPort", "10080");
|
||||
System.setProperty("proxyHost", "127.0.0.1");
|
||||
AuthRequest authRequest = new AuthTwitterRequest(AuthConfig.builder()
|
||||
.clientId("App ID")
|
||||
.clientSecret("App Key")
|
||||
.redirectUri("网站回调域")
|
||||
.build());
|
||||
```
|
||||
|
||||
> 特别注意:所有国外平台都无法直接通过java进行访问API,目前[simple-http](https://github.com/xkcoding/simple-http) Release版本,暂不支持添加代理,所以目前需要手动开启代理。
|
||||
|
||||
代理开启的方式:
|
||||
```java
|
||||
System.setProperty("proxyPort", "10080");
|
||||
System.setProperty("proxyHost", "127.0.0.1");
|
||||
```
|
||||
以上代码可以在声明 `AuthRequest` 时创建,也可以全局执行。
|
||||
|
||||
本地如果支持科学上网,就用自己本地的代理端口即可,如果不支持科学上网,可以去网上找一些免费的代理IP进行测试(请自行操作)。
|
||||
|
||||
### 2.3 生成授权地址
|
||||
|
||||
我们可以直接使用以下方式生成第三方平台的授权链接:
|
||||
```java
|
||||
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
|
||||
```
|
||||
这个链接我们可以直接后台重定向跳转,也可以返回到前端后,前端控制跳转。前端控制的好处就是,可以将第三方的授权页嵌入到iframe中,适配网站设计。
|
||||
|
||||
|
||||
### 2.4 以上完整代码如下
|
||||
|
||||
```java
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.request.AuthTwitterRequest;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/oauth")
|
||||
public class RestAuthController {
|
||||
|
||||
@RequestMapping("/render")
|
||||
public void renderAuth(HttpServletResponse response) throws IOException {
|
||||
AuthRequest authRequest = getAuthRequest();
|
||||
response.sendRedirect(authRequest.authorize(AuthStateUtils.createState()));
|
||||
}
|
||||
|
||||
@RequestMapping("/callback")
|
||||
public Object login(AuthCallback callback) {
|
||||
AuthRequest authRequest = getAuthRequest();
|
||||
return authRequest.login(callback);
|
||||
}
|
||||
|
||||
private AuthRequest getAuthRequest() {
|
||||
// 国外平台 目前必须要手动配置代理
|
||||
System.setProperty("proxyPort", "10080");
|
||||
System.setProperty("proxyHost", "127.0.0.1");
|
||||
return new AuthTwitterRequest(AuthConfig.builder()
|
||||
.clientId("App ID")
|
||||
.clientSecret("App Key")
|
||||
.redirectUri("网站回调域")
|
||||
.build());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 3. 授权结果
|
||||
|
||||
暂无
|
||||
@@ -0,0 +1,43 @@
|
||||
## OAuth 文档
|
||||
|
||||
关于OAuth2相关的内容、原理可以自行参阅以下资料:
|
||||
|
||||
- [The OAuth 2.0 Authorization Framework](https://tools.ietf.org/html/rfc6749)
|
||||
- [OAuth 2.0](https://oauth.net/2/)
|
||||
|
||||
## 第三方平台的API文档
|
||||
|
||||
- <a href="https://gitee.com/api/v5/oauth_doc#list_1" target="_blank">Gitee</a>
|
||||
- <a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/" target="_blank">Github</a>
|
||||
- <a href="https://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E" target="_blank">新浪微博</a>
|
||||
- <a href="https://open-doc.dingtalk.com/microapp/serverapi2/kymkv6" target="_blank">钉钉</a>
|
||||
- <a href="http://developer.baidu.com/wiki/index.php?title=docs/oauth" target="_blank">百度</a>
|
||||
- <a href="https://open.coding.net/references/oauth/" target="_blank">coding</a>
|
||||
- <a href="https://dev.tencent.com/help/doc/faq/b4e5b7aee786/oauth" target="_blank">腾讯云</a>
|
||||
- <a href="https://www.oschina.net/openapi/docs/oauth2_authorize" target="_blank">开源中国</a>
|
||||
- <a href="https://alipay.open.taobao.com/docs/doc.htm?spm=a219a.7629140.0.0.336d4b70GUKXOl&treeId=193&articleId=105809&docType=1" target="_blank">支付宝</a>
|
||||
- <a href="https://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token" target="_blank">QQ</a>
|
||||
- <a href="https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN" target="_blank">微信开放平台</a>
|
||||
- <a href="https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html" target="_blank">微信公众平台</a>
|
||||
- <a href="https://open.work.weixin.qq.com/api/doc#90000/90135/90664" target="_blank">企业微信</a>
|
||||
- <a href="https://open.taobao.com/doc.htm?spm=a219a.7386797.0.0.4e00669acnkQy6&source=search&docId=105590&docType=1" target="_blank">淘宝</a>
|
||||
- <a href="https://developers.google.com/identity/protocols/OpenIDConnect" target="_blank">Google</a>
|
||||
- <a href="https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow" target="_blank">Facebook</a>
|
||||
- <a href="https://www.douyin.com/platform/doc/m-2-1-1" target="_blank">抖音</a>
|
||||
- <a href="https://docs.microsoft.com/zh-cn/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context" target="_blank">领英</a>
|
||||
- <a href="https://docs.microsoft.com/zh-cn/graph/auth/" target="_blank">微软</a>
|
||||
- <a href="https://dev.mi.com/console/doc/detail?pId=711" target="_blank">小米</a>
|
||||
- <a href="https://open.mp.toutiao.com/#/resource?_k=y7mfgk" target="_blank">头条</a>
|
||||
- <a href="https://docs.teambition.com/" target="_blank">Teambition</a>
|
||||
- <a href="http://open.renren.com/wiki/OAuth2.0" target="_blank">人人</a>
|
||||
- <a href="https://developers.pinterest.com/docs/api/overview/?" target="_blank">Pinterest</a>
|
||||
- <a href="https://api.stackexchange.com/docs/authentication" target="_blank">StackOverflow</a>
|
||||
- <a href="https://developer.huawei.com/consumer/cn/devservice/doc/30101" target="_blank">华为</a>
|
||||
- <a href="https://open.kujiale.com/open/apps/2/docs?doc_id=95" target="_blank">酷家乐</a>
|
||||
- <a href="https://docs.gitlab.com/ee/api/oauth2.html" target="_blank">Gitlab</a>
|
||||
- <a href="http://open.waimai.meituan.com/openapi_docs/oauth/" target="_blank">美团</a>
|
||||
- <a href="https://open.shop.ele.me/openapi/documents/khd001" target="_blank">饿了么</a>
|
||||
- <a href="https://developer.twitter.com/en/docs/basics/authentication/guides/log-in-with-twitter" target="_blank">推特</a>
|
||||
- <a href="https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object" target="_blank">用户信息</a>
|
||||
- <a href="https://developer.twitter.com/en/docs/basics/response-codes" target="_blank">响应码</a>
|
||||
- <a href="https://developer.twitter.com/en/docs/basics/apps/guides/callback-urls" target="_blank">Callback Urls规则</a>
|
||||
@@ -13,3 +13,6 @@
|
||||
|
||||
<div style="clear: both;"></div>
|
||||
|
||||
<a href="https://www.producthunt.com/posts/justauth?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-justauth" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=196886&theme=dark" alt="JustAuth - Login, so easy! | Product Hunt Embed" style="width: 250px; height: 54px;" width="250px" height="54px" /></a>
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
## 1.15.3-alpha
|
||||
### 2020/05/13
|
||||
- 修复
|
||||
- 解决 Twitter 授权失败的BUG
|
||||
- 文档
|
||||
- 完善 [https://docs.justauth.whnb.wang](https://docs.justauth.whnb.wang/) 的404引导页内容
|
||||
- 增加名词解释: `uuid`
|
||||
- 补充 [Q&A](Q&A.md)
|
||||
- 新增 [参考文档](references.md),包含 OAuth 授权和第三方平台的API文档等内容
|
||||
- 新增 [推特登录](oauth/twitter.md) 的说明文档
|
||||
|
||||
> 特别注意:所有国外平台都无法直接通过java进行访问API,目前[simple-http](https://github.com/xkcoding/simple-http) Release版本,暂不支持添加代理,所以目前需要手动开启代理。
|
||||
|
||||
代理开启的方式:
|
||||
```java
|
||||
System.setProperty("proxyPort", "10080");
|
||||
System.setProperty("proxyHost", "127.0.0.1");
|
||||
```
|
||||
以上代码可以在声明 `AuthRequest` 时创建,也可以全局执行。
|
||||
|
||||
本地如果支持科学上网,就用自己本地的代理端口即可,如果不支持科学上网,可以去网上找一些免费的代理IP进行测试(请自行操作)。
|
||||
|
||||
|
||||
## 1.15.2-alpha
|
||||
### 2020/05/10
|
||||
- 修改
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.15.2-alpha</version>
|
||||
<version>1.15.4-alpha</version>
|
||||
|
||||
<name>JustAuth</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth</url>
|
||||
|
||||
@@ -48,12 +48,13 @@ public class AuthCallback implements Serializable {
|
||||
*
|
||||
* @since 1.13.0
|
||||
*/
|
||||
private String oauthToken;
|
||||
private String oauth_token;
|
||||
|
||||
/**
|
||||
* Twitter回调后返回的oauth_verifier
|
||||
*
|
||||
* @since 1.13.0
|
||||
*/
|
||||
private String oauthVerifier;
|
||||
private String oauth_verifier;
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,21 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
super(config, TWITTER, authStateCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state}
|
||||
*
|
||||
* @param state state 验证授权流程的参数,可以防止csrf
|
||||
* @return 返回授权地址
|
||||
* @since 1.9.3
|
||||
*/
|
||||
@Override
|
||||
public String authorize(String state) {
|
||||
AuthToken token = this.getRequestToken();
|
||||
return UrlBuilder.fromBaseUrl(source.authorize())
|
||||
.queryParam("oauth_token", token.getOauthToken())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtaining a request token
|
||||
* https://developer.twitter.com/en/docs/twitter-for-websites/log-in-with-twitter/guides/implementing-sign-in-with-twitter
|
||||
@@ -54,6 +69,9 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Authorization", header);
|
||||
httpHeader.add("User-Agent", "themattharris' HTTP Client");
|
||||
httpHeader.add("Host", "api.twitter.com");
|
||||
httpHeader.add("Accept", "*/*");
|
||||
String requestToken = HttpUtil.post(baseUrl, null, httpHeader);
|
||||
|
||||
Map<String, String> res = MapUtil.parseStringToMap(requestToken, false);
|
||||
@@ -74,10 +92,10 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
Map<String, String> oauthParams = buildOauthParams();
|
||||
oauthParams.put("oauth_token", authCallback.getOauthToken());
|
||||
oauthParams.put("oauth_verifier", authCallback.getOauthVerifier());
|
||||
oauthParams.put("oauth_token", authCallback.getOauth_token());
|
||||
oauthParams.put("oauth_verifier", authCallback.getOauth_verifier());
|
||||
oauthParams.put("oauth_signature", generateTwitterSignature(oauthParams, "POST", source.accessToken(), config.getClientSecret(), authCallback
|
||||
.getOauthToken()));
|
||||
.getOauth_token()));
|
||||
String header = buildHeader(oauthParams);
|
||||
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
@@ -85,7 +103,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
|
||||
Map<String, String> form = new HashMap<>(1);
|
||||
form.put("oauth_verifier", authCallback.getOauthVerifier());
|
||||
form.put("oauth_verifier", authCallback.getOauth_verifier());
|
||||
String response = HttpUtil.post(source.accessToken(), form, httpHeader, false);
|
||||
|
||||
Map<String, String> requestToken = MapUtil.parseStringToMap(response, false);
|
||||
@@ -127,6 +145,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
.avatar(userInfo.getString("profile_image_url_https"))
|
||||
.blog(userInfo.getString("url"))
|
||||
.location(userInfo.getString("location"))
|
||||
.avatar(userInfo.getString("profile_image_url"))
|
||||
.source(source.toString())
|
||||
.token(authToken)
|
||||
.build();
|
||||
@@ -152,15 +171,12 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
}
|
||||
|
||||
private String buildHeader(Map<String, String> oauthParams) {
|
||||
final StringBuilder sb = new StringBuilder(PREAMBLE);
|
||||
final StringBuilder sb = new StringBuilder(PREAMBLE + " ");
|
||||
|
||||
for (Map.Entry<String, String> param : oauthParams.entrySet()) {
|
||||
if (sb.length() > PREAMBLE.length()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(param.getKey()).append("=\"").append(urlEncode(param.getValue())).append('"');
|
||||
sb.append(param.getKey()).append("=\"").append(urlEncode(param.getValue())).append('"').append(", ");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
return sb.deleteCharAt(sb.length() - 2).toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,10 @@ public class AuthChecker {
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public static void checkCode(AuthSource source, AuthCallback callback) {
|
||||
// 推特平台不支持回调 code 和 state
|
||||
if (source == AuthDefaultSource.TWITTER) {
|
||||
return;
|
||||
}
|
||||
String code = callback.getCode();
|
||||
if (source == AuthDefaultSource.ALIPAY) {
|
||||
code = callback.getAuth_code();
|
||||
@@ -95,6 +99,10 @@ public class AuthChecker {
|
||||
* @param authStateCache {@code authStateCache} state缓存实现
|
||||
*/
|
||||
public static void checkState(String state, AuthSource source, AuthStateCache authStateCache) {
|
||||
// 推特平台不支持回调 code 和 state
|
||||
if (source == AuthDefaultSource.TWITTER) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isEmpty(state) || !authStateCache.containsKey(state)) {
|
||||
throw new AuthException(AuthResponseStatus.ILLEGAL_STATUS, source);
|
||||
}
|
||||
|
||||
@@ -92,20 +92,20 @@ public class GlobalAuthUtilsTest {
|
||||
.clientSecret("0YX3RH2DnPiT77pgzLzFdfpMKX8ENLIWQKYQ7lG5TERuZNgXN5")
|
||||
.build();
|
||||
AuthCallback authCallback = AuthCallback.builder()
|
||||
.oauthToken("W_KLmAAAAAAAxq5LAAABbXxJeD0")
|
||||
.oauthVerifier("lYou4gxfA6S5KioUa8VF8HCShzA2nSxp")
|
||||
.oauth_token("W_KLmAAAAAAAxq5LAAABbXxJeD0")
|
||||
.oauth_verifier("lYou4gxfA6S5KioUa8VF8HCShzA2nSxp")
|
||||
.build();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("oauth_consumer_key", config.getClientId());
|
||||
params.put("oauth_nonce", "sTj7Ivg73u052eXstpoS1AWQCynuDEPN");
|
||||
params.put("oauth_signature_method", "HMAC-SHA1");
|
||||
params.put("oauth_timestamp", "1569751082");
|
||||
params.put("oauth_token", authCallback.getOauthToken());
|
||||
params.put("oauth_verifier", authCallback.getOauthVerifier());
|
||||
params.put("oauth_token", authCallback.getOauth_token());
|
||||
params.put("oauth_verifier", authCallback.getOauth_verifier());
|
||||
params.put("oauth_version", "1.0");
|
||||
|
||||
params.put("oauth_signature", GlobalAuthUtils.generateTwitterSignature(params, "POST", TWITTER.accessToken(), config.getClientSecret(), authCallback
|
||||
.getOauthToken()));
|
||||
.getOauth_token()));
|
||||
|
||||
params.forEach((k, v) -> params.put(k, "\"" + GlobalAuthUtils.urlEncode(v) + "\""));
|
||||
String actual = "OAuth " + GlobalAuthUtils.parseMapToString(params, false).replaceAll("&", ", ");
|
||||
|
||||
Reference in New Issue
Block a user