diff options
| author | Jeroen Wijenbergh <jeroenwijenbergh@protonmail.com> | 2022-03-08 13:13:14 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-05 12:26:13 +0200 |
| commit | 5065de4cff907b70ea3446888a7bad243744a8ab (patch) | |
| tree | 32c610aca2865426415040c324beb2a2a52db756 /src/api.go | |
| parent | e2bcbc5d7fc8846ed189863ab33f0514f5399365 (diff) | |
OAuth: Begin implementation without OAuth2 lib
- We want to use as little dependencies as possible.
While the OAuth2 library is helpful, it is not needed.
Diffstat (limited to 'src/api.go')
| -rw-r--r-- | src/api.go | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -8,9 +8,9 @@ import ( ) type endpointList struct { - Endpoint string `json:"api_endpoint"` - AuthorizationEndpoint string `json:"authorization_endpoint"` - TokenEndpoint string `json:"token_endpoint"` + 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" @@ -52,8 +52,16 @@ func APIGetEndpoints(vpnState *EduVPNState) (*EduVPNEndpoints, error) { } func APIAuthenticatedInfo(vpnState *EduVPNState) (string, error) { - url := vpnState.Endpoints.API.V3.Endpoint + "/info" - resp, reqErr := vpnState.OAuth.client.Get(url) + url := vpnState.Endpoints.API.V3.API + "/info" + + client := &http.Client{} + req, reqErr := http.NewRequest(http.MethodGet, url, nil) + if reqErr != nil { + return "", reqErr + } + req.Header.Add("Authorization", "Bearer "+vpnState.OAuthToken.Access) + resp, reqErr := client.Do(req) + if reqErr != nil { return "", reqErr } @@ -64,6 +72,7 @@ func APIAuthenticatedInfo(vpnState *EduVPNState) (string, error) { if resp.StatusCode != http.StatusOK { return "", errors.New("HTTP code not ok") } + // Read the body body, readErr := ioutil.ReadAll(resp.Body) if readErr != nil { |
