@@ -2,39 +2,34 @@ package generates
22
33import (
44 "bytes"
5+ "encoding/base64"
56 "strconv"
67 "strings"
78
89 "github.com/LyricTian/go.uuid"
9- "gopkg.in/LyricTian/lib.v2"
1010 "gopkg.in/oauth2.v2"
1111)
1212
13- // NewAccessGenerate 创建访问令牌生成实例
13+ // NewAccessGenerate Create to generate the access token instance
1414func NewAccessGenerate () * AccessGenerate {
1515 return & AccessGenerate {}
1616}
1717
18- // AccessGenerate 访问令牌生成
18+ // AccessGenerate Generate the access token
1919type AccessGenerate struct {
2020}
2121
22- // Token 生成令牌
22+ // Token Based on the UUID generated token
2323func (ag * AccessGenerate ) Token (data * oauth2.GenerateBasic , isGenRefresh bool ) (access , refresh string , err error ) {
2424 buf := bytes .NewBufferString (data .Client .GetID ())
2525 buf .WriteString (data .UserID )
2626 buf .WriteString (strconv .FormatInt (data .CreateAt .UnixNano (), 10 ))
27- access , err = lib .NewEncryption (uuid .NewV3 (uuid .NewV4 (), buf .String ()).Bytes ()).MD5 ()
28- if err != nil {
29- return
30- }
31- access = strings .ToUpper (access )
27+
28+ access = base64 .URLEncoding .EncodeToString (uuid .NewV3 (uuid .NewV4 (), buf .String ()).Bytes ())
29+ access = strings .ToUpper (strings .TrimRight (access , "=" ))
3230 if isGenRefresh {
33- refresh , err = lib .NewEncryption (uuid .NewV5 (uuid .NewV4 (), buf .String ()).Bytes ()).Sha1 ()
34- if err != nil {
35- return
36- }
37- refresh = strings .ToUpper (refresh )
31+ refresh = base64 .URLEncoding .EncodeToString (uuid .NewV5 (uuid .NewV4 (), buf .String ()).Bytes ())
32+ refresh = strings .ToUpper (strings .TrimRight (refresh , "=" ))
3833 }
3934
4035 return
0 commit comments