forked from justauth/JustAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
264 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
本文将就JustAuth中涉及到的一些配置、关键词做一下简单说明,方便使用者理解、使用。 | ||
|
||
## 本文相关名词 | ||
|
||
- `调用者` 指使用`JustAuth`的开发者 | ||
- `第三方` 指开发者对接的第三方网站,比如:QQ平台、微信平台、微博平台 | ||
- `用户` 指最终服务的真实用户 | ||
|
||
## JustAuth中的关键词 | ||
|
||
以下内容了解后,将会使你更容易地上手JustAuth。 | ||
|
||
- `clientId` 客户端身份标识符(应用id),一般在申请完Oauth应用后,由**第三方平台颁发**,唯一 | ||
- `clientSecret` 客户端密钥,一般在申请完Oauth应用后,由**第三方平台颁发** | ||
- `redirectUri` **调用者项目中的有效api地址**。用户在确认第三方平台授权(登录)后,第三方平台会重定向到该地址,并携带code等参数 | ||
- `state` 用来保持授权会话流程完整性,防止CSRF攻击的安全的随机的参数,由**调用者生成** | ||
- `alipayPublicKey` 支付宝公钥。当选择支付宝登录时,必传该值,由**调用者生成** | ||
- `unionId` 是否需要申请unionid,目前只针对**qq登录**。注:qq授权登录时,获取unionid需要单独发送邮件申请权限。如果个人开发者账号中申请了该权限,可以将该值置为true,在获取openId时就会同步获取unionId。参考链接:[UnionID介绍](http://wiki.connect.qq.com/unionid%E4%BB%8B%E7%BB%8D) | ||
- `stackOverflowKey` Stack Overflow 登陆时需单独提供的key,由**第三方平台颁发** | ||
- `agentId` 企业微信登陆时需单独提供该值,由**第三方平台颁发**,为授权方的网页应用ID | ||
- `source` JustAuth支持的第三方平台,比如:GITHUB、GITEE等 | ||
|
||
## 参考资料 | ||
|
||
关于OAuth2相关的内容、原理可以自行参阅以下资料: | ||
|
||
- [The OAuth 2.0 Authorization Framework](https://tools.ietf.org/html/rfc6749) | ||
- [OAuth 2.0](https://oauth.net/2/) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
# 如何使用JustAuth集成一个平台 | ||
在前面有介绍到,JustAuth的特点之一就是**简**,极简主义,不给使用者造成不必要的障碍。 | ||
|
||
待补充 | ||
既然牛皮吹下了, 那么如何才能用JustAuth实现第三方登录呢? | ||
|
||
使用JustAuth总共分三步(**这三步也适合于任何一个支持的平台**): | ||
|
||
1. 申请注册第三方平台的开发者账号 | ||
2. 创建第三方平台的应用,获取配置信息(id, secret, callbackUrl) | ||
3. 使用该工具实现授权登陆 | ||
|
||
|
||
- 引入依赖 | ||
```xml | ||
<dependency> | ||
<groupId>me.zhyd.oauth</groupId> | ||
<artifactId>JustAuth</artifactId> | ||
<version>1.10.1</version> | ||
</dependency> | ||
``` | ||
- 调用api | ||
```java | ||
// 创建授权request | ||
AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder() | ||
.clientId("clientId") | ||
.clientSecret("clientSecret") | ||
.redirectUri("redirectUri") | ||
.build()); | ||
// 生成授权页面 | ||
authRequest.authorize(); | ||
// 授权登录后会返回code(auth_code(仅限支付宝))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的参数 | ||
// 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state | ||
authRequest.login(callback); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters