summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-12-12 13:22:02 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-12-12 13:39:20 +0100
commita8a2436975da7f8b8319da21f1ca3d93ebff08e8 (patch)
treecafb8ea807e66fe57c612883fa0c726cb429c7ac /internal
parent978b9b3eea99d58ad95692c35be15e27608a16ee (diff)
OAuth: Minor style changes
Diffstat (limited to 'internal')
-rw-r--r--internal/oauth/oauth.go18
-rw-r--r--internal/oauth/oauth_test.go16
-rw-r--r--internal/oauth/token.go4
3 files changed, 19 insertions, 19 deletions
diff --git a/internal/oauth/oauth.go b/internal/oauth/oauth.go
index 3dcd3d3..67d9c8a 100644
--- a/internal/oauth/oauth.go
+++ b/internal/oauth/oauth.go
@@ -30,13 +30,13 @@ import (
// client.
// We implement it similarly to the verifier.
func genState() (string, error) {
- bts, err := util.MakeRandomByteSlice(32)
+ bs, err := util.MakeRandomByteSlice(32)
if err != nil {
return "", err
}
// For consistency, we also use raw url encoding here
- return base64.RawURLEncoding.EncodeToString(bts), nil
+ return base64.RawURLEncoding.EncodeToString(bs), nil
}
// genChallengeS256 generates a sha256 base64 challenge from a verifier
@@ -65,12 +65,12 @@ func genChallengeS256(verifier string) string {
//
// See: https://datatracker.ietf.org/doc/html/rfc7636#section-4.1
func genVerifier() (string, error) {
- randomBytes, err := util.MakeRandomByteSlice(32)
+ random, err := util.MakeRandomByteSlice(32)
if err != nil {
return "", err
}
- return base64.RawURLEncoding.EncodeToString(randomBytes), nil
+ return base64.RawURLEncoding.EncodeToString(random), nil
}
// OAuth defines the main structure for this package.
@@ -122,18 +122,18 @@ type ExchangeSession struct {
// It returns the access token as a string, possibly obtained fresh using the Refresh Token
// If the token cannot be obtained, an error is returned and the token is an empty string.
func (oauth *OAuth) AccessToken() (string, error) {
- ts := oauth.token
+ t := oauth.token
// We have tokens...
// The tokens are not expired yet
// So they should be valid, re-login not needed
- if !ts.Expired() {
- return ts.access, nil
+ if !t.Expired() {
+ return t.access, nil
}
// Check if refresh is even possible by doing a simple check if the refresh token is empty
// This is not needed but reduces API calls to the server
- if ts.refresh == "" {
+ if t.refresh == "" {
return "", errors.Wrap(&TokensInvalidError{Cause: "no refresh token is present"}, 0)
}
@@ -146,7 +146,7 @@ func (oauth *OAuth) AccessToken() (string, error) {
}
// We have obtained new tokens with refresh
- return ts.access, nil
+ return t.access, nil
}
// setupListener sets up an OAuth listener
diff --git a/internal/oauth/oauth_test.go b/internal/oauth/oauth_test.go
index 693984e..c2c012a 100644
--- a/internal/oauth/oauth_test.go
+++ b/internal/oauth/oauth_test.go
@@ -6,22 +6,22 @@ import (
)
func Test_verifiergen(t *testing.T) {
- verifier, verifierErr := genVerifier()
- if verifierErr != nil {
- t.Fatalf("Gen verifier error: %v", verifierErr)
+ v, err := genVerifier()
+ if err != nil {
+ t.Fatalf("Gen verifier error: %v", err)
}
// Verifier must be at minimum 43 and at max 128 characters...
// However... Our verifier is exactly 43!
- if len(verifier) != 43 {
+ if len(v) != 43 {
t.Fatalf(
"Got verifier length: %d, want a verifier with at least 43 characters",
- len(verifier),
+ len(v),
)
}
- _, unescapeErr := url.QueryUnescape(verifier)
- if unescapeErr != nil {
- t.Fatalf("Verifier: %s can not be unescaped", verifier)
+ _, err = url.QueryUnescape(v)
+ if err != nil {
+ t.Fatalf("Verifier: %s can not be unescaped", v)
}
}
diff --git a/internal/oauth/token.go b/internal/oauth/token.go
index bd17647..31c2c74 100644
--- a/internal/oauth/token.go
+++ b/internal/oauth/token.go
@@ -31,6 +31,6 @@ type Token struct {
// Expired checks if the access token is expired.
func (tokens *Token) Expired() bool {
- currentTime := time.Now()
- return !currentTime.Before(tokens.expiredTimestamp)
+ now := time.Now()
+ return !now.Before(tokens.expiredTimestamp)
}