aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-11-26 10:54:50 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-11-26 10:54:50 +0100
commit51654c36cc74987edf0eec69c41964906250d68b (patch)
treeb3c2c527136cd5d099892692db3a4c114d89a1f8 /client
parent1a9d505710061196383e649f0918cca7cd41a066 (diff)
Add providers as top-level construct in auth.json
Diffstat (limited to 'client')
-rw-r--r--client/go/auth0/auth0.go45
1 files changed, 41 insertions, 4 deletions
diff --git a/client/go/auth0/auth0.go b/client/go/auth0/auth0.go
index aeac2e1a77a..52a1997d957 100644
--- a/client/go/auth0/auth0.go
+++ b/client/go/auth0/auth0.go
@@ -27,12 +27,22 @@ const accessTokenExpThreshold = 5 * time.Minute
var errUnauthenticated = errors.New("not logged in. Try 'vespa auth login'")
+type configJsonFormat struct {
+ Version int `json:"version"`
+ Providers providers `json:"providers"`
+}
+
+type providers struct {
+ Config config `json:"auth0"`
+}
+
type config struct {
+ Version int `json:"version"`
Systems map[string]System `json:"systems"`
}
type System struct {
- Name string `json:"name"`
+ Name string `json:"-"`
AccessToken string `json:"access_token,omitempty"`
Scopes []string `json:"scopes,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
@@ -271,7 +281,7 @@ func (a *Auth0) persistConfig() error {
}
}
- buf, err := json.MarshalIndent(a.config, "", " ")
+ buf, err := a.configToJson(&a.config)
if err != nil {
return err
}
@@ -283,6 +293,32 @@ func (a *Auth0) persistConfig() error {
return nil
}
+func (a *Auth0) configToJson(cfg *config) ([]byte, error) {
+ cfg.Version = 1
+ r := configJsonFormat{
+ Version: 1,
+ Providers: providers{
+ Config: *cfg,
+ },
+ }
+ return json.MarshalIndent(r, "", " ")
+}
+
+func (a *Auth0) jsonToConfig(buf []byte) (*config, error) {
+ r := configJsonFormat{}
+ if err := json.Unmarshal(buf, &r); err != nil {
+ return nil, err
+ }
+ cfg := r.Providers.Config
+ systems := cfg.Systems
+ if systems != nil {
+ for n, s := range systems {
+ s.Name = n
+ }
+ }
+ return &cfg, nil
+}
+
func (a *Auth0) init() error {
a.initOnce.Do(func() {
if a.errOnce = a.initContext(); a.errOnce != nil {
@@ -302,10 +338,11 @@ func (a *Auth0) initContext() (err error) {
return err
}
- if err := json.Unmarshal(buf, &a.config); err != nil {
+ cfg, err := a.jsonToConfig(buf)
+ if err != nil {
return err
}
-
+ a.config = *cfg
return nil
}