1
0
mirror of synced 2026-05-22 13:43:20 +00:00
Files
JustAuth/docs/how-to-use.md
T

33 lines
1.2 KiB
Markdown
Raw Normal View History

2019-08-23 20:05:26 +08:00
在前面有介绍到,JustAuth的特点之一就是**简**,极简主义,不给使用者造成不必要的障碍。
2019-08-03 14:35:51 +08:00
2019-08-23 20:05:26 +08:00
既然牛皮吹下了, 那么如何才能用JustAuth实现第三方登录呢?
2019-09-03 20:39:19 +08:00
使用JustAuth总共分三步(**这三步也适合于JustAuth支持的任何一个平台**):
2019-08-23 20:05:26 +08:00
1. 申请注册第三方平台的开发者账号
2019-09-03 20:39:19 +08:00
2. 创建第三方平台的应用,获取配置信息(`accessKey`, `secretKey`, `redirectUri`)
2019-08-23 20:05:26 +08:00
3. 使用该工具实现授权登陆
- 引入依赖
```xml
<dependency>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
2019-09-03 20:39:19 +08:00
<version>${latest.version}</version>
2019-08-23 20:05:26 +08:00
</dependency>
```
- 调用api
```java
// 创建授权request
AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.build());
// 生成授权页面
2019-09-03 09:14:50 +08:00
authRequest.authorize("state");
2019-08-23 20:05:26 +08:00
// 授权登录后会返回code(auth_code(仅限支付宝))、state1.8.0版本后,可以用AuthCallback类作为回调接口的参数
// 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
authRequest.login(callback);
```