summaryrefslogtreecommitdiff
path: root/src/api.go
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroenwijenbergh@protonmail.com>2022-03-08 13:13:14 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 12:26:13 +0200
commit5065de4cff907b70ea3446888a7bad243744a8ab (patch)
tree32c610aca2865426415040c324beb2a2a52db756 /src/api.go
parente2bcbc5d7fc8846ed189863ab33f0514f5399365 (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.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/api.go b/src/api.go
index 8bd2847..6a4596a 100644
--- a/src/api.go
+++ b/src/api.go
@@ -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 {