forked from openshift/osin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokengen.go
38 lines (30 loc) · 1.13 KB
/
tokengen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package osin
import (
"encoding/base64"
"strings"
"code.google.com/p/go-uuid/uuid"
)
// AuthorizeTokenGenDefault is the default authorization token generator
type AuthorizeTokenGenDefault struct {
}
func removePadding(token string) string {
return strings.TrimRight(token, "=")
}
// GenerateAuthorizeToken generates a base64-encoded UUID code
func (a *AuthorizeTokenGenDefault) GenerateAuthorizeToken(data *AuthorizeData) (ret string, err error) {
token := uuid.NewRandom()
return removePadding(base64.URLEncoding.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 = removePadding(base64.URLEncoding.EncodeToString([]byte(token)))
if generaterefresh {
rtoken := uuid.NewRandom()
refreshtoken = removePadding(base64.URLEncoding.EncodeToString([]byte(rtoken)))
}
return
}