Store account credentials

This commit is contained in:
Ben Toogood 2020-05-13 13:48:25 +01:00
parent 3fac7d79ab
commit 47c1cb433e
2 changed files with 11 additions and 1 deletions

View File

@ -250,8 +250,8 @@ func (s *service) registerAuthAccount() error {
if err != nil { if err != nil {
return err return err
} }
s.Options().Auth.Init(auth.ClientToken(token))
s.Options().Auth.Init(auth.ClientToken(token), auth.Credentials(acc.ID, acc.Secret))
logger.Infof("Auth [%v] Authenticated as %v", s.Options().Auth, name) logger.Infof("Auth [%v] Authenticated as %v", s.Options().Auth, name)
return nil return nil
} }

View File

@ -181,6 +181,16 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac
return callWithToken(tok.AccessToken) return callWithToken(tok.AccessToken)
} }
// generate a new token if we have credentials
if len(aaOpts.ID) > 0 && len(aaOpts.Secret) > 0 {
tok, err := aa.Token(auth.WithCredentials(aaOpts.ID, aaOpts.Secret))
if err != nil {
return err
}
aa.Init(auth.ClientToken(tok))
return callWithToken(tok.AccessToken)
}
// check to see if a token was provided in config, this is normally used for // check to see if a token was provided in config, this is normally used for
// setting the token when calling via the cli // setting the token when calling via the cli
if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 {