From 2d5c7dad599b3f8b70ab07382973c51d1de2193d Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Fri, 18 Mar 2022 13:58:08 +0100 Subject: Refactor: Structures changed and added Token refresh function --- src/api.go | 40 +++------------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) (limited to 'src/api.go') 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 -- cgit v1.2.3