diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-08-28 14:18:42 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2023-09-25 09:43:37 +0200 |
| commit | 492b74f2d20697816acc5e60d79f858a1360fb63 (patch) | |
| tree | cb25c1567a3f75c7b02323179e751d37ffc6e19a /internal/server | |
| parent | 6ba7dfdc36296e5699bec8d3cf6779ff7c69a53f (diff) | |
Server: Set OAuth endpoints on refresh
This fixes OAuth endpoints after e.g. an update from 2.x to 3.x
Diffstat (limited to 'internal/server')
| -rw-r--r-- | internal/server/server.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/internal/server/server.go b/internal/server/server.go index c971c72..e8b046f 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -17,6 +17,7 @@ import ( ) type Server interface { + // OAuth returns the struct used for OAuth OAuth() *oauth.OAuth // TemplateAuth returns the authorization URL template function @@ -227,14 +228,25 @@ func HasValidProfile(ctx context.Context, srv Server, wireguardSupport bool) (bo } func RefreshEndpoints(ctx context.Context, srv Server) error { - // Re-initialize the endpoints - // TODO: Make this a warning instead? + // Get the base struct b, err := srv.Base() if err != nil { return err } - return api.Endpoints(ctx, b) + // update the base struct + err = api.Endpoints(ctx, b) + if err != nil { + return err + } + + // update OAuth + auth := srv.OAuth() + if auth != nil { + auth.BaseAuthorizationURL = b.Endpoints.API.V3.Authorization + auth.TokenURL = b.Endpoints.API.V3.Token + } + return nil } func Config(ctx context.Context, server Server, wireguardSupport bool, preferTCP bool) (*ConfigData, error) { |
