diff options
| author | Jeroen Wijenbergh <jeroenwijenbergh@protonmail.com> | 2022-03-21 11:20:34 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-05 12:26:16 +0200 |
| commit | d45f5df4dc5fa9ad8abdc47c940f6baf96fdbe45 (patch) | |
| tree | c910ef87fc8464cd93978ce3cda5e3df87a30d5e /src/api.go | |
| parent | 2d5c7dad599b3f8b70ab07382973c51d1de2193d (diff) | |
OAuth: Make sure the tokens are not expired
Diffstat (limited to 'src/api.go')
| -rw-r--r-- | src/api.go | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -4,8 +4,15 @@ import ( "net/http" ) -func (eduvpn *VPNState) APIAuthenticatedInfo() (string, error) { - url := eduvpn.Server.Endpoints.API.V3.API + "/info" +func (eduvpn *VPNState) APIAuthenticatedGet(endpoint string) (string, error) { + url := eduvpn.Server.Endpoints.API.V3.API + endpoint + + // Ensure we have non-expired tokens + oauthErr := eduvpn.EnsureTokensOAuth() + + if oauthErr != nil { + return "", oauthErr + } headers := &http.Header{"Authorization": {"Bearer " + eduvpn.Server.OAuth.Token.Access}} body, bodyErr := HTTPGetWithOptionalParams(url, &HTTPOptionalParams{Headers: headers}) |
