authorize.go (819B)
1 package generates 2 3 import ( 4 "bytes" 5 "context" 6 "encoding/base64" 7 "strings" 8 9 "github.com/google/uuid" 10 "github.com/superseriousbusiness/oauth2/v4" 11 ) 12 13 // NewAuthorizeGenerate create to generate the authorize code instance 14 func NewAuthorizeGenerate() *AuthorizeGenerate { 15 return &AuthorizeGenerate{} 16 } 17 18 // AuthorizeGenerate generate the authorize code 19 type AuthorizeGenerate struct{} 20 21 // Token based on the UUID generated token 22 func (ag *AuthorizeGenerate) Token(ctx context.Context, data *oauth2.GenerateBasic) (string, error) { 23 buf := bytes.NewBufferString(data.Client.GetID()) 24 buf.WriteString(data.UserID) 25 token := uuid.NewMD5(uuid.Must(uuid.NewRandom()), buf.Bytes()) 26 code := base64.URLEncoding.EncodeToString([]byte(token.String())) 27 code = strings.ToUpper(strings.TrimRight(code, "=")) 28 29 return code, nil 30 }