From 4480416a3f4424eeefdf4117b7cf5120bfeafbcc Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Mon, 15 May 2023 14:10:55 +0200 Subject: Client + OAuth + Server: Initialize the OAuth clientID on add --- internal/oauth/oauth.go | 9 +++------ internal/oauth/oauth_test.go | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'internal/oauth') 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) -- cgit v1.2.3