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 | |
| parent | 680c91aff531fca6fa2394094252520adac5f9e3 (diff) | |
Client + OAuth + Server: Initialize the OAuth clientID on add
| -rw-r--r-- | client/client.go | 6 | ||||
| -rw-r--r-- | internal/oauth/oauth.go | 9 | ||||
| -rw-r--r-- | internal/oauth/oauth_test.go | 4 | ||||
| -rw-r--r-- | internal/server/custom/custom.go | 4 | ||||
| -rw-r--r-- | internal/server/institute/institute.go | 3 | ||||
| -rw-r--r-- | internal/server/list.go | 11 | ||||
| -rw-r--r-- | internal/server/secure/secure.go | 3 |
7 files changed, 20 insertions, 20 deletions
diff --git a/client/client.go b/client/client.go index e79f708..f17bf67 100644 --- a/client/client.go +++ b/client/client.go @@ -481,7 +481,7 @@ func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes. if err != nil { return err } - srv, err = c.Servers.AddInstituteAccess(ck.Context(), dSrv) + srv, err = c.Servers.AddInstituteAccess(ck.Context(), c.Name ,dSrv) if err != nil { return err } @@ -494,12 +494,12 @@ func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes. c.Discovery.MarkOrganizationsExpired() return err } - srv, err = c.Servers.AddSecureInternet(ck.Context(), dOrg, dSrv) + srv, err = c.Servers.AddSecureInternet(ck.Context(), c.Name, dOrg, dSrv) if err != nil { return err } case srvtypes.TypeCustom: - srv, err = c.Servers.AddCustom(ck.Context(), identifier) + srv, err = c.Servers.AddCustom(ck.Context(), c.Name, identifier) if err != nil { return err } 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) diff --git a/internal/server/custom/custom.go b/internal/server/custom/custom.go index d4a0508..af6ad67 100644 --- a/internal/server/custom/custom.go +++ b/internal/server/custom/custom.go @@ -16,7 +16,7 @@ type ( Servers = institute.Servers ) -func New(ctx context.Context, u string) (*Server, error) { +func New(ctx context.Context, clientID string, u string) (*Server, error) { pu, err := url.Parse(u) if err != nil { return nil, errors.WrapPrefix(err, "failed to parse custom server URL", 0) @@ -32,6 +32,6 @@ func New(ctx context.Context, u string) (*Server, error) { API := b.Endpoints.API.V3 s := &Server{Basic: b} - s.Auth.Init(u, API.Authorization, API.Token) + s.Auth.Init(clientID, u, API.Authorization, API.Token) return s, nil } diff --git a/internal/server/institute/institute.go b/internal/server/institute/institute.go index ada1977..e0a52b7 100644 --- a/internal/server/institute/institute.go +++ b/internal/server/institute/institute.go @@ -25,6 +25,7 @@ type Servers struct { func New( ctx context.Context, + clientID string, url string, name map[string]string, supportContact []string, @@ -41,7 +42,7 @@ func New( API := b.Endpoints.API.V3 s := &Server{Basic: b} - s.Auth.Init(url, API.Authorization, API.Token) + s.Auth.Init(clientID, url, API.Authorization, API.Token) return s, nil } diff --git a/internal/server/list.go b/internal/server/list.go index 2660102..f3ae4e8 100644 --- a/internal/server/list.go +++ b/internal/server/list.go @@ -44,8 +44,8 @@ func (l *List) Current() (Server, error) { return l.InstituteServers.Current() } -func (l *List) AddCustom(ctx context.Context, url string) (Server, error) { - srv, err := custom.New(ctx, url) +func (l *List) AddCustom(ctx context.Context, clientID string, url string) (Server, error) { + srv, err := custom.New(ctx, clientID, url) if err != nil { return nil, err } @@ -53,8 +53,8 @@ func (l *List) AddCustom(ctx context.Context, url string) (Server, error) { return srv, nil } -func (l *List) AddInstituteAccess(ctx context.Context, discoServer *discotypes.Server) (Server, error) { - srv, err := institute.New(ctx, discoServer.BaseURL, discoServer.DisplayName, discoServer.SupportContact) +func (l *List) AddInstituteAccess(ctx context.Context, clientID string, discoServer *discotypes.Server) (Server, error) { + srv, err := institute.New(ctx, clientID, discoServer.BaseURL, discoServer.DisplayName, discoServer.SupportContact) if err != nil { return nil, err } @@ -64,12 +64,13 @@ func (l *List) AddInstituteAccess(ctx context.Context, discoServer *discotypes.S func (l *List) AddSecureInternet( ctx context.Context, + clientID string, secureOrg *discotypes.Organization, secureServer *discotypes.Server, ) (*secure.Server, error) { // If we have specified an organization ID // We also need to get an authorization template - err := l.SecureInternetHomeServer.Init(ctx, secureOrg, secureServer) + err := l.SecureInternetHomeServer.Init(ctx, clientID, secureOrg, secureServer) if err != nil { return nil, err } diff --git a/internal/server/secure/secure.go b/internal/server/secure/secure.go index bdddb93..d25bf02 100644 --- a/internal/server/secure/secure.go +++ b/internal/server/secure/secure.go @@ -94,6 +94,7 @@ func (s *Server) Location(ctx context.Context, locSrv *discotypes.Server) error // Initializes the home server and adds its own location. func (s *Server) Init( ctx context.Context, + clientID string, homeOrg *discotypes.Organization, homeLoc *discotypes.Server, ) error { if s.HomeOrganizationID != homeOrg.OrgID { @@ -120,7 +121,7 @@ func (s *Server) Init( } // Make sure oauth contains our endpoints - s.Auth.Init(b.URL, b.Endpoints.API.V3.Authorization, b.Endpoints.API.V3.Token) + s.Auth.Init(clientID, b.URL, b.Endpoints.API.V3.Authorization, b.Endpoints.API.V3.Token) return nil } |
