parent
1035f72f72
commit
8daa385306
@ -0,0 +1,35 @@ |
||||
# JWT |
||||
|
||||
## 安装 |
||||
|
||||
```shell |
||||
go get git.tsl3060.com/openapi/go-security/jwt |
||||
``` |
||||
|
||||
将包放在你的项目文件夹下,并在 import 中添加以下内容: |
||||
|
||||
```golang |
||||
import jwt "git.tsl3060.com/openapi/go-security/jwt" |
||||
``` |
||||
|
||||
## 基本使用 |
||||
|
||||
### 获取服务器公钥 |
||||
|
||||
访问[https://opendev.tsl3060.com/certs/publickey](https://opendev.tsl3060.com/certs/publickey)以获取服务器公钥 |
||||
|
||||
### 配置并使用示例 |
||||
|
||||
```golang |
||||
// 设置公钥 |
||||
service, err := jwt.NewTokenService("public key") |
||||
if err != nil { |
||||
return |
||||
} |
||||
// 校验解析token |
||||
token, err := service.VerifyToken("token") |
||||
if err != nil { |
||||
return |
||||
} |
||||
fmt.Println(token) |
||||
``` |
@ -1,9 +0,0 @@ |
||||
-----BEGIN PUBLIC KEY----- |
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuZ63ry9k3F2WExbOqaM7 |
||||
Kuacqt7U4ja5x6BomSoMp2TpgTRXOvTAMH+etRkqKDDPoHoNl23vryPQpx6v4tLn |
||||
7onqhBexGV8EWjWyWkBOGI9LBvhjG5eWWwisnpUNlbeYUBanzxJEm6Fx0hqKK7Xy |
||||
OXiwA0FotL7OEhfHaTEsp18EXkGSih9tZejLU5GITH26h/9sAz9Frdwe6NhZm712 |
||||
s8H7r63/ecd522JHqdVbmg7nj0dCwJ5fWLx1pnbDfaGD8PR7sfRSWs6f2NHBKgRk |
||||
8sdD4l7Q38bpBIwhAjRiwWsj3+RQhS5BoTjunvysrMS1J6/nfQi97yJoedWUz2DS |
||||
BQIDAQAB |
||||
-----END PUBLIC KEY----- |
@ -0,0 +1,23 @@ |
||||
package test |
||||
|
||||
import ( |
||||
"fmt" |
||||
"git.tsl3060.com/openapi/go-security/jwt" |
||||
"testing" |
||||
) |
||||
|
||||
func Test_Jwt(t *testing.T) { |
||||
t.Run("test jwt", func(t *testing.T) { |
||||
// 设置公钥
|
||||
service, err := jwt.NewTokenService("public key") |
||||
if err != nil { |
||||
return |
||||
} |
||||
// 校验解析token
|
||||
token, err := service.VerifyToken("token") |
||||
if err != nil { |
||||
return |
||||
} |
||||
fmt.Println(token) |
||||
}) |
||||
} |
Loading…
Reference in new issue