diff options
| author | Jeroen Wijenbergh <jeroenwijenbergh@protonmail.com> | 2024-05-08 11:49:19 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-05-08 13:54:45 +0000 |
| commit | 9ce4e4458794290755c68a180125acc68ab84038 (patch) | |
| tree | d4211e55bd77d07938651619733c7b435597d53a /internal | |
| parent | 580f94b4023fba35ab2f58d2e6d7b3b7c40ec139 (diff) | |
Server: Add a way to pass OAuth start time
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/server/custom.go | 15 | ||||
| -rw-r--r-- | internal/server/institute.go | 16 | ||||
| -rw-r--r-- | internal/server/secureinternet.go | 17 |
3 files changed, 36 insertions, 12 deletions
diff --git a/internal/server/custom.go b/internal/server/custom.go index a35cbab..dabf9e5 100644 --- a/internal/server/custom.go +++ b/internal/server/custom.go @@ -2,6 +2,7 @@ package server import ( "context" + "time" "github.com/eduvpn/eduvpn-common/internal/api" "github.com/eduvpn/eduvpn-common/internal/config/v2" @@ -13,8 +14,8 @@ import ( // AddCustom adds a custom server to the internal server list // `ctx` is the context used for cancellation // `id` is the identifier of the server, the base URL -// `na` specifies whether or not we want to add the server without doing authorization now -func (s *Servers) AddCustom(ctx context.Context, id string, na bool) error { +// `ot` specifies specifies the start time OAuth was already triggered +func (s *Servers) AddCustom(ctx context.Context, id string, ot *int64) error { sd := api.ServerData{ ID: id, Type: server.TypeCustom, @@ -22,13 +23,19 @@ func (s *Servers) AddCustom(ctx context.Context, id string, na bool) error { BaseAuthWK: id, } - err := s.config.AddServer(id, server.TypeCustom, v2.Server{}) + auth := time.Time{} + if ot != nil { + auth = time.Unix(*ot, 0) + } + err := s.config.AddServer(id, server.TypeCustom, v2.Server{ + LastAuthorizeTime: auth, + }) if err != nil { return err } // no authorization should be triggered, return - if na { + if ot != nil { return nil } diff --git a/internal/server/institute.go b/internal/server/institute.go index 7cb399f..caae004 100644 --- a/internal/server/institute.go +++ b/internal/server/institute.go @@ -2,6 +2,7 @@ package server import ( "context" + "time" "github.com/eduvpn/eduvpn-common/internal/api" "github.com/eduvpn/eduvpn-common/internal/config/v2" @@ -15,8 +16,8 @@ import ( // `ctx` is the context used for cancellation // `disco` are the discovery servers // `id` is the identifier for the server, the base url -// `na` is true when authorization should not be triggered -func (s *Servers) AddInstitute(ctx context.Context, disco *discovery.Discovery, id string, na bool) error { +// `ot` specifies specifies the start time OAuth was already triggered +func (s *Servers) AddInstitute(ctx context.Context, disco *discovery.Discovery, id string, ot *int64) error { // This is basically done to double check if the server is part of the institute access section of disco dsrv, err := disco.ServerByURL(id, "institute_access") if err != nil { @@ -30,13 +31,20 @@ func (s *Servers) AddInstitute(ctx context.Context, disco *discovery.Discovery, BaseAuthWK: dsrv.BaseURL, } - err = s.config.AddServer(dsrv.BaseURL, server.TypeInstituteAccess, v2.Server{}) + auth := time.Time{} + if ot != nil { + auth = time.Unix(*ot, 0) + } + + err = s.config.AddServer(dsrv.BaseURL, server.TypeInstituteAccess, v2.Server{ + LastAuthorizeTime: auth, + }) if err != nil { return err } // no authorization should be triggered, return - if na { + if ot != nil { return nil } diff --git a/internal/server/secureinternet.go b/internal/server/secureinternet.go index 4b9c29e..746dd4f 100644 --- a/internal/server/secureinternet.go +++ b/internal/server/secureinternet.go @@ -3,6 +3,7 @@ package server import ( "context" "errors" + "time" "github.com/eduvpn/eduvpn-common/internal/api" "github.com/eduvpn/eduvpn-common/internal/config/v2" @@ -17,8 +18,8 @@ import ( // `ctx` is the context used for cancellation // `disco` are the discovery servers // `orgID` is the organiztaion ID -// `na` specifies whether or not authorization should be triggered when adding -func (s *Servers) AddSecure(ctx context.Context, disco *discovery.Discovery, orgID string, na bool) error { +// `ot` specifies specifies the start time OAuth was already triggered +func (s *Servers) AddSecure(ctx context.Context, disco *discovery.Discovery, orgID string, ot *int64) error { if s.config.HasSecureInternet() { return errors.New("a secure internet server already exists") } @@ -41,13 +42,21 @@ func (s *Servers) AddSecure(ctx context.Context, disco *discovery.Discovery, org }, } - err = s.config.AddServer(orgID, server.TypeSecureInternet, v2.Server{CountryCode: dsrv.CountryCode}) + auth := time.Time{} + if ot != nil { + auth = time.Unix(*ot, 0) + } + + err = s.config.AddServer(orgID, server.TypeSecureInternet, v2.Server{ + CountryCode: dsrv.CountryCode, + LastAuthorizeTime: auth, + }) if err != nil { return err } // no authorization should be triggered, return - if na { + if ot != nil { return nil } |
