summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/fsm.go2
-rw-r--r--internal/oauth.go13
-rw-r--r--internal/server.go4
3 files changed, 18 insertions, 1 deletions
diff --git a/internal/fsm.go b/internal/fsm.go
index 5aa3f50..e848cae 100644
--- a/internal/fsm.go
+++ b/internal/fsm.go
@@ -106,7 +106,7 @@ func (fsm *FSM) Init(name string, callback func(string, string, string), logger
DEREGISTERED: {{NO_SERVER, "Client registers"}},
NO_SERVER: {{CHOSEN_SERVER, "User chooses a server"}},
CHOSEN_SERVER: {{AUTHENTICATED, "Found tokens in config"}, {OAUTH_STARTED, "No tokens found in config"}},
- OAUTH_STARTED: {{AUTHENTICATED, "User authorizes with browser"}},
+ OAUTH_STARTED: {{AUTHENTICATED, "User authorizes with browser"}, {CHOSEN_SERVER, "Cancel OAuth"}},
AUTHENTICATED: {{OAUTH_STARTED, "Re-authenticate with OAuth"}, {REQUEST_CONFIG, "Client requests a config"}},
REQUEST_CONFIG: {{ASK_PROFILE, "Multiple profiles found"}, {HAS_CONFIG, "Success, only one profile"}},
ASK_PROFILE: {{HAS_CONFIG, "User chooses profile and success"}},
diff --git a/internal/oauth.go b/internal/oauth.go
index 16edd1e..a49b492 100644
--- a/internal/oauth.go
+++ b/internal/oauth.go
@@ -271,6 +271,7 @@ func (oauth *OAuth) Finish() error {
return errors.New("invalid state to finish oauth")
}
tokenErr := oauth.getTokensWithCallback()
+
if tokenErr != nil {
return tokenErr
}
@@ -278,6 +279,11 @@ func (oauth *OAuth) Finish() error {
return nil
}
+func (oauth *OAuth) Cancel() {
+ oauth.Session.CallbackError = &OAuthCancelledCallbackError{}
+ oauth.Session.Server.Shutdown(oauth.Session.Context)
+}
+
func (oauth *OAuth) Login(name string, authorizationURL string, tokenURL string) error {
authInitializeErr := oauth.start(name, authorizationURL, tokenURL)
@@ -320,6 +326,13 @@ func (oauth *OAuth) NeedsRelogin() bool {
return true
}
+type OAuthCancelledCallbackError struct {
+}
+
+func (e *OAuthCancelledCallbackError) Error() string {
+ return fmt.Sprintf("Client cancelled OAuth")
+}
+
type OAuthGenStateUnableError struct {
Err error
}
diff --git a/internal/server.go b/internal/server.go
index 48a0e85..aa21a97 100644
--- a/internal/server.go
+++ b/internal/server.go
@@ -33,6 +33,10 @@ func (servers *Servers) GetCurrentServer() (*Server, error) {
return server, nil
}
+func (server *Server) CancelOAuth() {
+ server.OAuth.Cancel()
+}
+
func (server *Server) Init(url string, fsm *FSM, logger *FileLogger) error {
server.BaseURL = url
server.FSM = fsm