From 75aa163ccf407e9690f9ea0e548f8fed70073722 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Tue, 26 Apr 2022 15:43:35 +0200 Subject: OAuth: Add a Cancel method --- state.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'state.go') diff --git a/state.go b/state.go index 29f8a1e..8fbc7d2 100644 --- a/state.go +++ b/state.go @@ -81,6 +81,20 @@ func (state *VPNState) Deregister() error { return nil } +func (state *VPNState) CancelOAuth() error { + if !state.FSM.InState(internal.OAUTH_STARTED) { + return errors.New("cannot cancel oauth, oauth not started") + } + + server, serverErr := state.Servers.GetCurrentServer() + + if serverErr != nil { + return serverErr + } + server.CancelOAuth() + return nil +} + func (state *VPNState) Connect(url string) (string, error) { if state.FSM.InState(internal.DEREGISTERED) { return "", errors.New("app not registered") @@ -99,6 +113,9 @@ func (state *VPNState) Connect(url string) (string, error) { loginErr := server.Login() if loginErr != nil { + // We are possibly in oauth started + // So go to chosen server + state.FSM.GoTransition(internal.CHOSEN_SERVER) return "", loginErr } } else { // OAuth was valid, ensure we are in the authenticated state -- cgit v1.2.3