forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtokengen.go
45 lines (33 loc) · 926 Bytes
/
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
39
40
41
42
43
44
45
package osinserver
import (
"strings"
"github.com/RangelReale/osin"
"github.com/openshift/origin/pkg/oauthserver/server/crypto"
)
var (
_ osin.AuthorizeTokenGen = TokenGen{}
_ osin.AccessTokenGen = TokenGen{}
)
func randomToken() string {
for {
// guaranteed to have no / characters and no trailing ='s
token := crypto.Random256BitsString()
// Don't generate tokens with leading dashes... they're hard to use on the command line
if strings.HasPrefix(token, "-") {
continue
}
return token
}
}
type TokenGen struct{}
func (TokenGen) GenerateAuthorizeToken(data *osin.AuthorizeData) (ret string, err error) {
return randomToken(), nil
}
func (TokenGen) GenerateAccessToken(data *osin.AccessData, generaterefresh bool) (string, string, error) {
accesstoken := randomToken()
refreshtoken := ""
if generaterefresh {
refreshtoken = randomToken()
}
return accesstoken, refreshtoken, nil
}