forked from mohabusama/identityserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
30 lines (26 loc) · 1.01 KB
/
client.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
package oauthservice
import (
"crypto/rand"
"encoding/base64"
)
//Oauth2Client is an oauth2 client
type Oauth2Client struct {
ClientID string
Label string //Label is a just a tag to identity the secret for this ClientID
Secret string
CallbackURL string
ClientCredentialsGrantType bool //ClientCredentialsGrantType indicates if this client can be used in an oauth2 client credentials grant flow
}
//NewOauth2Client creates a new NewOauth2Client with a random secret
func NewOauth2Client(clientID, label, callbackURL string, clientCredentialsGrantType bool) *Oauth2Client {
c := &Oauth2Client{
ClientID: clientID,
Label: label,
CallbackURL: callbackURL,
ClientCredentialsGrantType: clientCredentialsGrantType,
}
randombytes := make([]byte, 39) //Multiple of 3 to make sure no padding is added
rand.Read(randombytes)
c.Secret = base64.URLEncoding.EncodeToString(randombytes)
return c
}