summaryrefslogtreecommitdiff
path: root/src/oauth.go
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroenwijenbergh@protonmail.com>2022-03-21 14:58:58 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-20 20:29:52 +0200
commitfc56f8770923ec1997444a8318a18be0a8397520 (patch)
tree3c6522b9b6e44ca2ad6cd94b074da78eed2c1028 /src/oauth.go
parentd45f5df4dc5fa9ad8abdc47c940f6baf96fdbe45 (diff)
Wireguard: Add basic support
Diffstat (limited to 'src/oauth.go')
-rw-r--r--src/oauth.go35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/oauth.go b/src/oauth.go
index bbe34af..063034b 100644
--- a/src/oauth.go
+++ b/src/oauth.go
@@ -54,8 +54,8 @@ func genVerifier() (string, error) {
}
type OAuth struct {
- Session *OAuthExchangeSession
- Token *OAuthToken
+ Session *OAuthExchangeSession
+ Token *OAuthToken
TokenURL string
}
@@ -65,13 +65,13 @@ type OAuthExchangeSession struct {
CallbackError error
// filled in in initialize
- ClientID string
- State string
- Verifier string
+ ClientID string
+ State string
+ Verifier string
// filled in when constructing the callback
- Context context.Context
- Server *http.Server
+ Context context.Context
+ Server *http.Server
}
func generateTimeSeconds() int64 {
@@ -81,10 +81,10 @@ func generateTimeSeconds() int64 {
// Struct that defines the json format for /.well-known/vpn-user-portal"
type OAuthToken struct {
- Access string `json:"access_token"`
- Refresh string `json:"refresh_token"`
- Type string `json:"token_type"`
- Expires int64 `json:"expires_in"`
+ Access string `json:"access_token"`
+ Refresh string `json:"refresh_token"`
+ Type string `json:"token_type"`
+ Expires int64 `json:"expires_in"`
ExpiredTimestamp int64
}
@@ -121,9 +121,9 @@ func (oauth *OAuth) getTokensWithAuthCode(authCode string) error {
}
headers := &http.Header{
"content-type": {"application/x-www-form-urlencoded"}}
- opts := &HTTPOptionalParams{Headers: headers}
+ opts := &HTTPOptionalParams{Headers: headers, Body: data}
current_time := generateTimeSeconds()
- body, bodyErr := HTTPPostWithOptionalParams(reqURL, data, opts)
+ body, bodyErr := HTTPPostWithOpts(reqURL, opts)
if bodyErr != nil {
return bodyErr
}
@@ -158,9 +158,9 @@ func (oauth *OAuth) getTokensWithRefresh() error {
}
headers := &http.Header{
"content-type": {"application/x-www-form-urlencoded"}}
- opts := &HTTPOptionalParams{Headers: headers}
+ opts := &HTTPOptionalParams{Headers: headers, Body: data}
current_time := generateTimeSeconds()
- body, bodyErr := HTTPPostWithOptionalParams(reqURL, data, opts)
+ body, bodyErr := HTTPPostWithOpts(reqURL, opts)
if bodyErr != nil {
return bodyErr
}
@@ -260,7 +260,6 @@ func (eduvpn *VPNState) InitializeOAuth() (string, error) {
return authURL, nil
}
-
// Error definitions
func (eduvpn *VPNState) FinishOAuth() error {
oauth := eduvpn.Server.OAuth
@@ -277,12 +276,11 @@ func (eduvpn *VPNState) EnsureTokensOAuth() error {
}
if oauth.isTokensExpired() {
- return oauth.getTokensWithRefresh();
+ return oauth.getTokensWithRefresh()
}
return nil
}
-
type OAuthGenStateUnableError struct {
Err error
}
@@ -299,7 +297,6 @@ func (e *OAuthGenVerifierUnableError) Error() string {
return fmt.Sprintf("failed generating verifier with error %v", e.Err)
}
-
type OAuthFailedCallbackError struct {
Addr string
Err error