summaryrefslogtreecommitdiff
path: root/src/api.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-18 13:58:08 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 12:26:16 +0200
commit2d5c7dad599b3f8b70ab07382973c51d1de2193d (patch)
tree3ca48a1104f958f896813a4d70093cdc27429133 /src/api.go
parent343836597df3efd6f31a68e29ff82b6ec4979f69 (diff)
Refactor: Structures changed and added Token refresh function
Diffstat (limited to 'src/api.go')
-rw-r--r--src/api.go40
1 files changed, 3 insertions, 37 deletions
diff --git a/src/api.go b/src/api.go
index ef07dd4..43e92d7 100644
--- a/src/api.go
+++ b/src/api.go
@@ -1,47 +1,13 @@
package eduvpn
import (
- "encoding/json"
"net/http"
)
-type endpointList struct {
- API string `json:"api_endpoint"`
- Authorization string `json:"authorization_endpoint"`
- Token string `json:"token_endpoint"`
-}
-
-// Struct that defines the json format for /.well-known/vpn-user-portal"
-type EduVPNEndpoints struct {
- API struct {
- V2 endpointList `json:"http://eduvpn.org/api#2"`
- V3 endpointList `json:"http://eduvpn.org/api#3"`
- } `json:"api"`
- V string `json:"v"`
-}
-
-func APIGetEndpoints(vpnState *EduVPNState) (*EduVPNEndpoints, error) {
- url := vpnState.Server + "/.well-known/vpn-user-portal"
- body, bodyErr := HTTPGet(url)
-
- if bodyErr != nil {
- return nil, bodyErr
- }
-
- structure := &EduVPNEndpoints{}
- jsonErr := json.Unmarshal(body, &structure)
-
- if jsonErr != nil {
- return nil, jsonErr
- }
-
- return structure, nil
-}
-
-func APIAuthenticatedInfo(vpnState *EduVPNState) (string, error) {
- url := vpnState.Endpoints.API.V3.API + "/info"
+func (eduvpn *VPNState) APIAuthenticatedInfo() (string, error) {
+ url := eduvpn.Server.Endpoints.API.V3.API + "/info"
- headers := &http.Header{"Authorization": {"Bearer " + vpnState.OAuthToken.Access}}
+ headers := &http.Header{"Authorization": {"Bearer " + eduvpn.Server.OAuth.Token.Access}}
body, bodyErr := HTTPGetWithOptionalParams(url, &HTTPOptionalParams{Headers: headers})
if bodyErr != nil {
return "", bodyErr