summaryrefslogtreecommitdiff
path: root/internal/oauth/oauth.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-12-20 15:43:55 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-12-21 18:28:50 +0100
commit12838c19514459974cf0a71c42f1248b1cb9419c (patch)
treea4254d20bb7b0ef49a2fa6c12753eb4c5acb64d1 /internal/oauth/oauth.go
parent6981666c6d8f639a1ff9c09a3bc08769e19928af (diff)
Exports + OAuth + Server: Forward tokens to getting a config
Diffstat (limited to 'internal/oauth/oauth.go')
-rw-r--r--internal/oauth/oauth.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/internal/oauth/oauth.go b/internal/oauth/oauth.go
index ce86337..6d21c82 100644
--- a/internal/oauth/oauth.go
+++ b/internal/oauth/oauth.go
@@ -196,10 +196,19 @@ func (oauth *OAuth) SetTokenExpired() {
// SetTokenRenew sets the tokens for renewal by completely clearing the structure.
func (oauth *OAuth) SetTokenRenew() {
if oauth.token != nil {
- oauth.token.Clear()
+ oauth.token.Update(Token{})
}
}
+func (oauth *OAuth) Token() Token {
+ t := Token{}
+ if oauth.token != nil {
+ t = oauth.token.Get()
+ }
+
+ return t
+}
+
// tokensWithAuthCode gets the access and refresh tokens using the authorization code
// Access tokens: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-04#section-1.4
// Refresh tokens: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-04#section-1.3.2
@@ -239,10 +248,17 @@ func (oauth *OAuth) tokensWithAuthCode(authCode string) error {
return errors.New("No token response after authorization code")
}
- oauth.token.Update(*tr, now)
+ oauth.token.UpdateResponse(*tr, now)
return nil
}
+func (oauth *OAuth) UpdateTokens(t Token) {
+ if oauth.token == nil {
+ oauth.token = &tokenLock{t: &tokenRefresher{Refresher: oauth.refreshResponse}}
+ }
+ oauth.token.Update(t)
+}
+
// refreshResponse gets the refresh token response with a refresh token
// This response contains the access and refresh tokens, together with a timestamp
// Access tokens: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-04#section-1.4
@@ -420,8 +436,8 @@ func (oauth *OAuth) AuthURL(name string, postProcessAuth func(string) string) (s
return "", errors.WrapPrefix(err, "genState error", 0)
}
- // Fill the oauth tokens
- oauth.token = &tokenLock{t: &token{Refresher: oauth.refreshResponse}}
+ // Re-initialize the token structure
+ oauth.UpdateTokens(Token{})
// Fill the struct with the necessary fields filled for the next call to getting the HTTP client
oauth.session = exchangeSession{