From 557cb4aa3ecb48800957c0f9f68571a11746d9fb Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Wed, 10 Aug 2022 11:55:43 +0200 Subject: State + Python: Implement renewing a session --- state.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'state.go') 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 -- cgit v1.2.3