diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-05-15 14:10:55 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2023-09-25 09:43:37 +0200 |
| commit | 4480416a3f4424eeefdf4117b7cf5120bfeafbcc (patch) | |
| tree | 5fd7283c492f2ceb709432d1c571ae29b1d8b161 /internal/oauth | |
| parent | 680c91aff531fca6fa2394094252520adac5f9e3 (diff) | |
Client + OAuth + Server: Initialize the OAuth clientID on add
Diffstat (limited to 'internal/oauth')
| -rw-r--r-- | internal/oauth/oauth.go | 9 | ||||
| -rw-r--r-- | internal/oauth/oauth_test.go | 4 |
2 files changed, 5 insertions, 8 deletions
diff --git a/internal/oauth/oauth.go b/internal/oauth/oauth.go index cee6599..4a873f1 100644 --- a/internal/oauth/oauth.go +++ b/internal/oauth/oauth.go @@ -101,9 +101,6 @@ type OAuth struct { // exchangeSession is a structure that gets passed to the callback for easy access to the current state. type exchangeSession struct { - // ClientID is the ID of the OAuth client - ClientID string - // ISS indicates the issuer identifier ISS string @@ -237,7 +234,7 @@ func (oauth *OAuth) tokensWithAuthCode(ctx context.Context, authCode string) err } data := url.Values{ - "client_id": {oauth.session.ClientID}, + "client_id": {oauth.ClientID}, "code": {authCode}, "code_verifier": {oauth.session.Verifier}, "grant_type": {"authorization_code"}, @@ -432,7 +429,8 @@ func (oauth *OAuth) Handler(w http.ResponseWriter, req *http.Request) { // - OAuth server issuer identification // - The URL used for authorization // - The URL to obtain new tokens. -func (oauth *OAuth) Init(iss string, baseAuthorizationURL string, tokenURL string) { +func (oauth *OAuth) Init(clientID string, iss string, baseAuthorizationURL string, tokenURL string) { + oauth.ClientID = clientID oauth.ISS = iss oauth.BaseAuthorizationURL = baseAuthorizationURL oauth.TokenURL = tokenURL @@ -469,7 +467,6 @@ func (oauth *OAuth) AuthURL(name string, postProcessAuth func(string) string) (s // Fill the struct with the necessary fields filled for the next call to getting the HTTP client oauth.session = exchangeSession{ - ClientID: name, ISS: oauth.ISS, State: state, Verifier: v, diff --git a/internal/oauth/oauth_test.go b/internal/oauth/oauth_test.go index 1f2a29e..4818f42 100644 --- a/internal/oauth/oauth_test.go +++ b/internal/oauth/oauth_test.go @@ -175,8 +175,8 @@ func Test_AuthURL(t *testing.T) { } // Check if the OAuth session has valid values - if o.session.ClientID != id { - t.Fatalf("OAuth ClientID not equal, want: %v, got: %v", o.session.ClientID, id) + if o.ClientID != id { + t.Fatalf("OAuth ClientID not equal, want: %v, got: %v", o.ClientID, id) } if o.session.ISS != iss { t.Fatalf("OAuth ISS not equal, want: %v, got: %v", o.session.ISS, iss) |
