summaryrefslogtreecommitdiff
path: root/internal/oauth.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-26 15:43:35 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-26 15:43:35 +0200
commit75aa163ccf407e9690f9ea0e548f8fed70073722 (patch)
treedd68386a24c8c479149d094bb209fb0a78071c06 /internal/oauth.go
parenta5d33f95ba68263e6c0ca758c5b854530332d9ae (diff)
OAuth: Add a Cancel method
Diffstat (limited to 'internal/oauth.go')
-rw-r--r--internal/oauth.go13
1 files changed, 13 insertions, 0 deletions
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
}