summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/client.go5
-rw-r--r--client/server.go11
-rw-r--r--internal/discovery/discovery.go12
-rw-r--r--internal/server/servers.go5
4 files changed, 30 insertions, 3 deletions
diff --git a/client/client.go b/client/client.go
index 6dae665..c443528 100644
--- a/client/client.go
+++ b/client/client.go
@@ -188,6 +188,11 @@ func (c *Client) DiscoOrganizations() (orgs *types.DiscoveryOrganizations, err e
return nil, errors.Errorf("discovery with Let's Connect is not supported")
}
+ // Mark organizations as expired if we have not set an organization yet
+ if !c.Servers.HasSecureInternet() {
+ c.Discovery.MarkOrganizationsExpired()
+ }
+
return c.Discovery.Organizations()
}
diff --git a/client/server.go b/client/server.go
index bf4ad6a..c136913 100644
--- a/client/server.go
+++ b/client/server.go
@@ -258,6 +258,10 @@ func (c *Client) AddSecureInternetHomeServer(orgID string) (srv server.Server, e
// Get the secure internet URL from discovery
org, dSrv, err := c.Discovery.SecureHomeArgs(orgID)
if err != nil {
+ // We mark the organizations as expired because we got an error
+ // Note that in the docs it states that it only should happen when the Org ID doesn't exist
+ // However, this is nice as well because it also catches the error where the SecureInternetHome server is not found
+ c.Discovery.MarkOrganizationsExpired()
c.goBackInternal()
return nil, err
}
@@ -554,6 +558,13 @@ func (c *Client) ensureLogin(srv server.Server, ct oauth.Token) (err error) {
return nil
}
+ // Mark organizations as expired if the server is a secure internet server
+ b, err := srv.Base()
+ // We only try to update it when we found the server base
+ if err == nil && b.Type == "secure_internet" {
+ c.Discovery.MarkOrganizationsExpired()
+ }
+
// Tokens are not valid or the client gave an error when updating tokens
// Otherwise, do the OAuth exchange
var url string
diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go
index 41685ac..f4151a7 100644
--- a/internal/discovery/discovery.go
+++ b/internal/discovery/discovery.go
@@ -73,13 +73,19 @@ func (discovery *Discovery) file(jsonFile string, previousVersion uint64, struct
return nil
}
+// MarkOrganizationsExpired marks the organizations as expired
+func (discovery *Discovery) MarkOrganizationsExpired() {
+ // Re-initialize the timestamp to zero
+ discovery.organizations.Timestamp = time.Time{}
+}
+
// DetermineOrganizationsUpdate returns a boolean indicating whether or not the discovery organizations should be updated
// FIXME: Implement based on
// https://github.com/eduvpn/documentation/blob/v3/SERVER_DISCOVERY.md
// - [IMPLEMENTED] on "first launch" when offering the search for "Institute Access" and "Organizations";
-// - [TODO] when the user tries to add new server AND the user did NOT yet choose an organization before;
-// - [TODO] when the authorization for the server associated with an already chosen organization is triggered, e.g. after expiry or revocation.
-// - [IMPLEMENTED using a custom error message] NOTE: when the org_id that the user chose previously is no longer available in organization_list.json the application should ask the user to choose their organization (again). This can occur for example when the organization replaced their identity provider, uses a different domain after rebranding or simply ceased to exist.
+// - [IMPLEMENTED in client/server.go] when the user tries to add new server AND the user did NOT yet choose an organization before;
+// - [IMPLEMENTED in client/server.go] when the authorization for the server associated with an already chosen organization is triggered, e.g. after expiry or revocation.
+// - [IMPLEMENTED using a custom error message, and in client/server.go] NOTE: when the org_id that the user chose previously is no longer available in organization_list.json the application should ask the user to choose their organization (again). This can occur for example when the organization replaced their identity provider, uses a different domain after rebranding or simply ceased to exist.
func (discovery *Discovery) DetermineOrganizationsUpdate() bool {
return discovery.organizations.Timestamp.IsZero()
}
diff --git a/internal/server/servers.go b/internal/server/servers.go
index 4086738..0fa8187 100644
--- a/internal/server/servers.go
+++ b/internal/server/servers.go
@@ -13,6 +13,11 @@ type Servers struct {
IsType Type `json:"is_secure_internet"`
}
+// HasSecureInternet returns whether or not we have a secure internet server added
+func (ss *Servers) HasSecureInternet() bool {
+ return len(ss.SecureInternetHomeServer.BaseMap) > 0
+}
+
func (ss *Servers) AddSecureInternet(
secureOrg *types.DiscoveryOrganization,
secureServer *types.DiscoveryServer,