summaryrefslogtreecommitdiff
path: root/state.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-08-10 11:55:43 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-08-10 11:55:43 +0200
commit557cb4aa3ecb48800957c0f9f68571a11746d9fb (patch)
tree05f6b51dca42a2b1876adfc7a908c8a06aa2de58 /state.go
parent93a95d4be4d754a901ab42a8174ae0e725680a01 (diff)
State + Python: Implement renewing a session
Diffstat (limited to 'state.go')
-rw-r--r--state.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/state.go b/state.go
index 7f29369..c046185 100644
--- a/state.go
+++ b/state.go
@@ -7,8 +7,10 @@ import (
"github.com/jwijenbergh/eduvpn-common/internal/discovery"
"github.com/jwijenbergh/eduvpn-common/internal/fsm"
"github.com/jwijenbergh/eduvpn-common/internal/log"
+ "github.com/jwijenbergh/eduvpn-common/internal/oauth"
"github.com/jwijenbergh/eduvpn-common/internal/server"
"github.com/jwijenbergh/eduvpn-common/internal/types"
+ "github.com/jwijenbergh/eduvpn-common/internal/util"
)
type VPNState struct {
@@ -388,6 +390,33 @@ func (state *VPNState) SetDisconnected() error {
return nil
}
+func (state *VPNState) RenewSession() error {
+ errorMessage := "failed to renew session"
+
+ currentServer, currentServerErr := state.Servers.GetCurrentServer()
+
+ if currentServerErr != nil {
+ return &types.WrappedErrorMessage{Message: "failed to renew session", Err: currentServerErr}
+ }
+
+ oauthStructure := currentServer.GetOAuth()
+ oauthStructure.Token = oauth.OAuthToken{Access: "",Refresh: "",Type: "",Expires: 0,ExpiredTimestamp: util.GetCurrentTime()}
+ // Make sure the FSM is initialized
+ oauthStructure.FSM = &state.FSM
+
+ loginErr := server.Login(currentServer)
+
+ if loginErr != nil {
+ // We are possibly in oauth started
+ // Go back
+ state.GoBack()
+ return &types.WrappedErrorMessage{Message: errorMessage, Err: loginErr}
+ }
+
+ return nil
+}
+
+
func (state *VPNState) ShouldRenewButton() bool {
if !state.FSM.InState(fsm.CONNECTED) {
return false