hanayo/vendor/github.com/RangelReale/osin/tokengen.go
2019-02-23 13:29:15 +00:00

34 lines
1015 B
Go

package osin
import (
"encoding/base64"
"github.com/pborman/uuid"
)
// AuthorizeTokenGenDefault is the default authorization token generator
type AuthorizeTokenGenDefault struct {
}
// GenerateAuthorizeToken generates a base64-encoded UUID code
func (a *AuthorizeTokenGenDefault) GenerateAuthorizeToken(data *AuthorizeData) (ret string, err error) {
token := uuid.NewRandom()
return base64.RawURLEncoding.EncodeToString([]byte(token)), nil
}
// AccessTokenGenDefault is the default authorization token generator
type AccessTokenGenDefault struct {
}
// GenerateAccessToken generates base64-encoded UUID access and refresh tokens
func (a *AccessTokenGenDefault) GenerateAccessToken(data *AccessData, generaterefresh bool) (accesstoken string, refreshtoken string, err error) {
token := uuid.NewRandom()
accesstoken = base64.RawURLEncoding.EncodeToString([]byte(token))
if generaterefresh {
rtoken := uuid.NewRandom()
refreshtoken = base64.RawURLEncoding.EncodeToString([]byte(rtoken))
}
return
}