-
Notifications
You must be signed in to change notification settings - Fork 0
/
uaa_token_refresher.go
45 lines (38 loc) · 1.1 KB
/
uaa_token_refresher.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 uaatokenrefresher
import (
"fmt"
"github.com/cloudfoundry-community/firehose-to-syslog/logging"
"github.com/cloudfoundry-incubator/uaago"
)
type UAATokenRefresher struct {
url string
clientID string
clientSecret string
skipSSLValidation bool
client *uaago.Client
}
func NewUAATokenRefresher(authEndpoint string,
clientID string,
clientSecret string,
skipSSLValidation bool,
) (*UAATokenRefresher, error) {
client, err := uaago.NewClient(authEndpoint)
if err != nil {
return &UAATokenRefresher{}, err
}
return &UAATokenRefresher{
url: authEndpoint,
clientID: clientID,
clientSecret: clientSecret,
skipSSLValidation: skipSSLValidation,
client: client,
}, nil
}
func (uaa *UAATokenRefresher) RefreshAuthToken() (string, error) {
authToken, err := uaa.client.GetAuthToken(uaa.clientID, uaa.clientSecret, uaa.skipSSLValidation)
if err != nil {
logging.LogStd(fmt.Sprint("Error getting oauth token: %s. Please check your Client ID and Secret.", err.Error()), false)
return "", err
}
return authToken, nil
}