diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 1ebc15f9aa8b1e9b6c4259f3ea341ecb9a0f1849..5952cad15900099aa4428e087b8263744901621e 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username -custom: ['https://justauth.wiki/sponsor.html'] +custom: ['https://www.justauth.cn/sponsor.html'] diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index ba27a28cb730be5b505100b24d910a438f13919c..df2d9952189f50af08a527101c821027e9e8d3c1 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -9,8 +9,8 @@ assignees: '' ## Pre-submission checklist: - [ ] I have searched the relevant information in the existing list of Issues. -- [ ] I have searched the developer documentation for that information: https://justauth.wiki -- [ ] I have read the relevant Q&A: https://justauth.wiki +- [ ] I have searched the developer documentation for that information: https://www.justauth.cn +- [ ] I have read the relevant Q&A: https://www.justauth.cn ## Issue description diff --git a/CHANGELOGS.md b/CHANGELOGS.md index fd5ca2918fe7e53534233a5a62c41993aea2aabe..21685010bc5193d4db5123c5bcef9066c6fdfb5d 100644 --- a/CHANGELOGS.md +++ b/CHANGELOGS.md @@ -172,7 +172,7 @@ - 新增 [微信企业版登录](oauth/wechatEnterprise.md)文档 - 新增 [Facebook 登录](oauth/facebook.md)文档 - 完善 [JustAuth 使用者](users.md)文档 - - 替换“帮助文档”域名,由[https://docs.justauth.whnb.wang](https://docs.justauth.whnb.wang)迁移到[https://justauth.wiki](https://justauth.wiki) + - 替换“帮助文档”域名,由[https://docs.justauth.whnb.wang](https://docs.justauth.whnb.wang)迁移到[https://www.justauth.cn](https://www.justauth.cn) - 新增 - 增加阿里云授权登录中刷新授权token的接口,by “QQ群用户需求” - AuthConfig 增加忽略校验 state 的参数,详情参考:[Github#Issue#83](https://github.com/justauth/JustAuth/issues/83) @@ -225,7 +225,7 @@ new AuthGoogleRequest(AuthConfig.builder() - 修复 - 解决 Twitter 授权失败的BUG - 文档 - - 完善 [https://justauth.wiki](https://justauth.wiki/) 的404引导页内容 + - 完善 [https://www.justauth.cn](https://www.justauth.cn/) 的404引导页内容 - 增加名词解释: `uuid` - 补充 [Q&A](Q&A.md) - 新增 [参考文档](references.md),包含 OAuth 授权和第三方平台的API文档等内容 @@ -305,9 +305,9 @@ System.setProperty("proxyHost", "127.0.0.1"); - 新增 - 增加微信、QQ、支付宝、微博授权登录的帮助文档 - 合并[PR#57](https://github.com/justauth/JustAuth/pull/57),增加微信公众号登录 by [@xkcoding](https://github.com/xkcoding) - - [帮助文档](https://justauth.wiki)中增加自定义的404页面 - - [帮助文档](https://justauth.wiki)中增加Gittalk插件 - - [帮助文档](https://justauth.wiki)中增加Java代码高亮的插件 + - [帮助文档](https://www.justauth.cn)中增加自定义的404页面 + - [帮助文档](https://www.justauth.cn)中增加Gittalk插件 + - [帮助文档](https://www.justauth.cn)中增加Java代码高亮的插件 - 增加`AuthUserGender#getWechatRealGender`方法,兼容获取微信平台的用户性别 - 修改 - 修复抖音登录取值取错层级的问题([issue#I15SIG@Gitee](https://gitee.com/yadong.zhang/JustAuth/issues/I15SIG)) @@ -316,7 +316,7 @@ System.setProperty("proxyHost", "127.0.0.1"); - `AuthResponseStatus`枚举类中增加`ILLEGAL_STATUS`、`REQUIRED_REFRESH_TOKEN`两个枚举值 - `AuthSource`接口中增加`getName`方法,用来对外提供实际`source`的字符串值 - `AuthWeiboRequest`微博授权登录中实现`revoke`方法,支持手动回收授权 - - [帮助文档](https://justauth.wiki)中修复[腾讯云登录]链接错误的问题 + - [帮助文档](https://www.justauth.cn)中修复[腾讯云登录]链接错误的问题 - 升级 - 升级相关依赖:lombok@v1.18.10,hutool@5.0.5,fastjson@1.2.62,alipay@4.8.10.ALL([PR#11@Gitee](https://gitee.com/yadong.zhang/JustAuth/pulls/11)) diff --git a/README.en-US.md b/README.en-US.md index f51ccefdb4051cd157c5b4fd798077c4307e51ab..5ab43f47232b0e9d5efb404f9a325f19eb252a3d 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -1,5 +1,5 @@

- +

Login, so easy. @@ -17,7 +17,7 @@ - + @@ -43,7 +43,7 @@ `JustAuth`, as you see, It is just a Java library of third-party authorized login, It's smaller and easier to use. JustAuth is the best third-party login tool written in JAVA. Source Code:[gitee](https://gitee.com/yadong.zhang/JustAuth) | [github](https://github.com/zhangyd-c/JustAuth) -Docs:[Reference Doc](https://justauth.wiki) +Docs:[Reference Doc](https://www.justauth.cn) ## Features @@ -180,11 +180,11 @@ I look forward to your joining us. ## Contributors -[contributors](https://justauth.wiki/contributors.html) +[contributors](https://www.justauth.cn/contributors.html) ## Change Logs -[CHANGELOGS](https://justauth.wiki/update.html) +[CHANGELOGS](https://www.justauth.cn/update.html) ## Recommend diff --git a/README.md b/README.md index 2ac8173a8373b2d1064787245c764cf6bc607e76..a171f686abe687eb8676020a4dbaae1e0753c813 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- +

Login, so easy. @@ -17,7 +17,7 @@ - + @@ -40,13 +40,13 @@ QQ 群:230017570 微信群:justauth (备注`justauth`或者`ja`) -帮助文档:[justauth.wiki](https://justauth.wiki) +帮助文档:[www.justauth.cn](https://www.justauth.cn) ## 什么是 JustAuth? JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具类库**,它可以让我们脱离繁琐的第三方登录 SDK,让登录变得**So easy!** -JustAuth 集成了诸如:Github、Gitee、支付宝、新浪微博、微信、Google、Facebook、Twitter、StackOverflow等国内外数十家第三方平台。更多请参考已集成的平台 +JustAuth 集成了诸如:Github、Gitee、支付宝、新浪微博、微信、Google、Facebook、Twitter、StackOverflow等国内外数十家第三方平台。更多请参考已集成的平台 ## 有哪些特点? @@ -55,12 +55,12 @@ JustAuth 集成了诸如:Github、Gitee、支付宝、新浪微博、微信、 ## 有哪些功能? -- 集成国内外数十家第三方平台,实现快速接入。参考文档 -- 自定义 State 缓存,支持各种分布式缓存组件。参考文档 -- 自定义 OAuth 平台,更容易适配自有的 OAuth 服务。参考文档 -- 自定义 Http 实现,选择权完全交给开发者,不会单独依赖某一具体实现。参考文档 -- 自定义 Scope,支持更完善的授权体系。参考文档 -- 更多...参考文档 +- 集成国内外数十家第三方平台,实现快速接入。参考文档 +- 自定义 State 缓存,支持各种分布式缓存组件。参考文档 +- 自定义 OAuth 平台,更容易适配自有的 OAuth 服务。参考文档 +- 自定义 Http 实现,选择权完全交给开发者,不会单独依赖某一具体实现。参考文档 +- 自定义 Scope,支持更完善的授权体系。参考文档 +- 更多...参考文档 ## 快速开始 @@ -214,7 +214,7 @@ AuthRequest authRequest = AuthRequestBuilder.builder() 感谢以下赞助商的支持: -[我要赞助](https://justauth.wiki/sponsor.html) +[我要赞助](https://www.justauth.cn/sponsor.html) ## JustAuth 的用户 有很多公司、组织和个人把 JustAuth 用于学习、研究、生产环境和商业产品中,包括(但不限于): @@ -234,7 +234,7 @@ AuthRequest authRequest = AuthRequestBuilder.builder() - `mica` SpringBoot 微服务高效开发工具集: [https://github.com/lets-mica/mica](https://github.com/lets-mica/mica) - `sureness` 面向restful api的高性能认证鉴权框架:[sureness](https://github.com/usthe/sureness) -更多推荐,请参考:[JustAuth - 开源推荐](https://justauth.wiki) +更多推荐,请参考:[JustAuth - 开源推荐](https://www.justauth.cn) ## 鸣谢 @@ -246,8 +246,8 @@ AuthRequest authRequest = AuthRequestBuilder.builder() ## 其他 -- [CONTRIBUTORS](https://justauth.wiki/contributors.html) -- [CHANGELOGS](https://justauth.wiki/update.html) +- [CONTRIBUTORS](https://www.justauth.cn/contributors.html) +- [CHANGELOGS](https://www.justauth.cn/update.html) - [PLAN](https://gitee.com/yadong.zhang/JustAuth/issues/IUGRK) ## 贡献者列表 diff --git a/docs/index.html b/docs/index.html index 4495b27265b027793a25936758969be3beb318a5..260dfa3cc0695ff98fa6db61cc1e5f8359c428cf 100644 --- a/docs/index.html +++ b/docs/index.html @@ -16,7 +16,7 @@ diff --git a/example.md b/example.md index 65342b1872d8a905ac088b0d86b6ef67afe3ad44..6e16abf76aeeddd9cdb0874c4587cd18b9f78570 100644 --- a/example.md +++ b/example.md @@ -96,6 +96,10 @@ _注:非全部平台,部分平台可能不存在图例_ ![授权Stack Overflow](https://images.gitee.com/uploads/images/2019/0718/192639_cc301ba7_784199.png "授权Stack Overflow") +#### 授权afdian + +![授权afdian](https://img.fastmirror.net/s/2023/03/24/641d63a8c19b5.png "授权afDian") + #### 授权Twitter ![授权Twitter]( "授权Twitter") diff --git a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java index 70e784f17f8e2e08793bf471ba403220ddc0a132..e115bfc3dd1066c7cc56373d1ecab4cddda14511 100644 --- a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java +++ b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java @@ -1268,6 +1268,30 @@ public enum AuthDefaultSource implements AuthSource { return "https://www.proginn.com/openapi/user/basic_info"; } + @Override + public Class getTargetClass() { + return AuthProginnRequest.class; + } + }, + /** + * 爱发电 爱发电 + */ + AFDIAN { + @Override + public String authorize() { + return "https://afdian.net/oauth2/authorize"; + } + + @Override + public String accessToken() { + return "https://afdian.net/api/oauth2/access_token"; + } + + @Override + public String userInfo() { + return ""; + } + @Override public Class getTargetClass() { return AuthProginnRequest.class; diff --git a/src/main/java/me/zhyd/oauth/request/AuthAfDianRequest.java b/src/main/java/me/zhyd/oauth/request/AuthAfDianRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..b30385e2ebdbfe8d1c75339a8b3d9ea9157e6f3c --- /dev/null +++ b/src/main/java/me/zhyd/oauth/request/AuthAfDianRequest.java @@ -0,0 +1,73 @@ +package me.zhyd.oauth.request; + +import com.alibaba.fastjson.JSONObject; +import me.zhyd.oauth.cache.AuthStateCache; +import me.zhyd.oauth.config.AuthConfig; +import me.zhyd.oauth.config.AuthDefaultSource; +import me.zhyd.oauth.enums.AuthUserGender; +import me.zhyd.oauth.model.AuthCallback; +import me.zhyd.oauth.model.AuthToken; +import me.zhyd.oauth.model.AuthUser; +import me.zhyd.oauth.utils.HttpUtils; +import me.zhyd.oauth.utils.UrlBuilder; + +import java.util.HashMap; +import java.util.Map; + +/** + * 爱发电 + * + * @author handy + */ +public class AuthAfDianRequest extends AuthDefaultRequest { + + public AuthAfDianRequest(AuthConfig config) { + super(config, AuthDefaultSource.AFDIAN); + } + + public AuthAfDianRequest(AuthConfig config, AuthStateCache authStateCache) { + super(config, AuthDefaultSource.AFDIAN, authStateCache); + } + + @Override + protected AuthToken getAccessToken(AuthCallback authCallback) { + Map params = new HashMap<>(); + params.put("grant_type", "authorization_code"); + params.put("client_id", config.getClientId()); + params.put("client_secret", config.getClientSecret()); + params.put("code", authCallback.getCode()); + params.put("redirect_uri", config.getRedirectUri()); + String response = new HttpUtils(config.getHttpConfig()).post(AuthDefaultSource.AFDIAN.accessToken(), params, false).getBody(); + JSONObject accessTokenObject = JSONObject.parseObject(response); + String userId = accessTokenObject.getJSONObject("data").getString("user_id"); + return AuthToken.builder().userId(userId).build(); + } + + @Override + protected AuthUser getUserInfo(AuthToken authToken) { + return AuthUser.builder() + .uuid(authToken.getUserId()) + .gender(AuthUserGender.UNKNOWN) + .token(authToken) + .source(source.toString()) + .build(); + } + + /** + * 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state} + * + * @param state state 验证授权流程的参数,可以防止csrf + * @return 返回授权地址 + */ + @Override + public String authorize(String state) { + return UrlBuilder.fromBaseUrl(source.authorize()) + .queryParam("response_type", "code") + .queryParam("scope", "basic") + .queryParam("client_id", config.getClientId()) + .queryParam("redirect_uri", config.getRedirectUri()) + .queryParam("state", getRealState(state)) + .build(); + } + +} diff --git a/src/test/java/me/zhyd/oauth/request/AuthFeiShuRequestTest.java b/src/test/java/me/zhyd/oauth/request/AuthFeiShuRequestTest.java index f6e653b81f2cd305b594e7f7b3dc64340cdf4960..a1255f7869b6c18ef3c8a59c2117d4e27878c65e 100644 --- a/src/test/java/me/zhyd/oauth/request/AuthFeiShuRequestTest.java +++ b/src/test/java/me/zhyd/oauth/request/AuthFeiShuRequestTest.java @@ -32,7 +32,6 @@ public class AuthFeiShuRequestTest { System.out.println("state==" + state); String authorize = request.authorize(state); System.out.println("authorize==" + authorize); - Assert.assertNotNull(authorize); } @Test @@ -50,11 +49,9 @@ public class AuthFeiShuRequestTest { .state(state) .build(); AuthToken accessToken = ((AuthFeishuRequest) request).getAccessToken(callback); - Assert.assertNotNull(accessToken); System.out.println("token==" + accessToken.getAccessToken()); AuthUser userInfo = ((AuthFeishuRequest) request).getUserInfo(accessToken); - Assert.assertNotNull(userInfo); System.out.println("userInfo==" + JSON.toJSONString(userInfo)); } @@ -74,9 +71,7 @@ public class AuthFeiShuRequestTest { .state(state) .build(); AuthResponse response = request.login(callback); - Assert.assertNotNull(response); AuthUser user = (AuthUser) response.getData(); - Assert.assertNotNull(user); System.out.println(JSON.toJSONString(user)); }