diff --git a/internal/auth/auth.go b/internal/auth/auth.go index a85c4426e..866e6b134 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -19,7 +19,8 @@ const ( oauthTokenEndpoint = "https://auth0.auth0.com/oauth/token" audiencePath = "/api/v2/" - secretsNamespace = "auth0-cli" + // namespace used to set/get values from the keychain + SecretsNamespace = "auth0-cli" ) var requiredScopes = []string{ @@ -31,25 +32,22 @@ var requiredScopes = []string{ "read:client_keys", "read:logs", } -// SecretStore provides secure storage for sensitive data +// SecretStore provides access to stored sensitive data. type SecretStore interface { - // Set sets the secret - Set(namespace, key, value string) error // Get gets the secret Get(namespace, key string) (string, error) // Delete removes the secret Delete(namespace, key string) error } -type Authenticator struct { - Secrets SecretStore -} +type Authenticator struct{} type Result struct { - Tenant string - Domain string - AccessToken string - ExpiresIn int64 + Tenant string + Domain string + RefreshToken string + AccessToken string + ExpiresIn int64 } type State struct { @@ -122,17 +120,12 @@ func (a *Authenticator) Wait(ctx context.Context, state State) (Result, error) { return Result{}, fmt.Errorf("cannot parse tenant from the given access token: %w", err) } - // store the refresh token - err = a.Secrets.Set(secretsNamespace, ten, res.RefreshToken) - if err != nil { - return Result{}, fmt.Errorf("cannot store refresh token: %w", err) - } - return Result{ - AccessToken: res.AccessToken, - ExpiresIn: res.ExpiresIn, - Tenant: ten, - Domain: domain, + RefreshToken: res.RefreshToken, + AccessToken: res.AccessToken, + ExpiresIn: res.ExpiresIn, + Tenant: ten, + Domain: domain, }, nil } } diff --git a/internal/auth/mock/auth.go b/internal/auth/mock/auth.go index 97ac03c84..cc189f03f 100644 --- a/internal/auth/mock/auth.go +++ b/internal/auth/mock/auth.go @@ -32,20 +32,6 @@ func (m *MockSecretStore) EXPECT() *MockSecretStoreMockRecorder { return m.recorder } -// Set mocks base method -func (m *MockSecretStore) Set(namespace, key, value string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Set", namespace, key, value) - ret0, _ := ret[0].(error) - return ret0 -} - -// Set indicates an expected call of Set -func (mr *MockSecretStoreMockRecorder) Set(namespace, key, value interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockSecretStore)(nil).Set), namespace, key, value) -} - // Get mocks base method func (m *MockSecretStore) Get(namespace, key string) (string, error) { m.ctrl.T.Helper() diff --git a/internal/auth/secrets.go b/internal/auth/secrets.go index d3967107b..86203ad1b 100644 --- a/internal/auth/secrets.go +++ b/internal/auth/secrets.go @@ -1,6 +1,8 @@ package auth -import "github.com/zalando/go-keyring" +import ( + "github.com/zalando/go-keyring" +) type Keyring struct{} diff --git a/internal/auth/token.go b/internal/auth/token.go index 3395810d9..66424a3e6 100644 --- a/internal/auth/token.go +++ b/internal/auth/token.go @@ -24,14 +24,14 @@ type TokenRetriever struct { // Delete deletes the given tenant from the secrets storage. func (t *TokenRetriever) Delete(tenant string) error { - return t.Secrets.Delete(secretsNamespace, tenant) + return t.Secrets.Delete(SecretsNamespace, tenant) } // Refresh gets a new access token from the provided refresh token, // The request is used the default client_id and endpoint for device authentication. func (t *TokenRetriever) Refresh(ctx context.Context, tenant string) (TokenResponse, error) { // get stored refresh token: - refreshToken, err := t.Secrets.Get(secretsNamespace, tenant) + refreshToken, err := t.Secrets.Get(SecretsNamespace, tenant) if err != nil { return TokenResponse{}, fmt.Errorf("cannot get the stored refresh token: %w", err) } diff --git a/internal/auth0/actions_mock.go b/internal/auth0/actions_mock.go new file mode 100644 index 000000000..4c19b92d1 --- /dev/null +++ b/internal/auth0/actions_mock.go @@ -0,0 +1,376 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: actions.go + +// Package auth0 is a generated GoMock package. +package auth0 + +import ( + gomock "github.com/golang/mock/gomock" + management "gopkg.in/auth0.v5/management" + reflect "reflect" +) + +// MockActionAPI is a mock of ActionAPI interface +type MockActionAPI struct { + ctrl *gomock.Controller + recorder *MockActionAPIMockRecorder +} + +// MockActionAPIMockRecorder is the mock recorder for MockActionAPI +type MockActionAPIMockRecorder struct { + mock *MockActionAPI +} + +// NewMockActionAPI creates a new mock instance +func NewMockActionAPI(ctrl *gomock.Controller) *MockActionAPI { + mock := &MockActionAPI{ctrl: ctrl} + mock.recorder = &MockActionAPIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockActionAPI) EXPECT() *MockActionAPIMockRecorder { + return m.recorder +} + +// Create mocks base method +func (m *MockActionAPI) Create(a *management.Action) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", a) + ret0, _ := ret[0].(error) + return ret0 +} + +// Create indicates an expected call of Create +func (mr *MockActionAPIMockRecorder) Create(a interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockActionAPI)(nil).Create), a) +} + +// Read mocks base method +func (m *MockActionAPI) Read(id string) (*management.Action, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", id) + ret0, _ := ret[0].(*management.Action) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read +func (mr *MockActionAPIMockRecorder) Read(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockActionAPI)(nil).Read), id) +} + +// Update mocks base method +func (m *MockActionAPI) Update(id string, a *management.Action) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", id, a) + ret0, _ := ret[0].(error) + return ret0 +} + +// Update indicates an expected call of Update +func (mr *MockActionAPIMockRecorder) Update(id, a interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockActionAPI)(nil).Update), id, a) +} + +// Delete mocks base method +func (m *MockActionAPI) Delete(id string, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Delete", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete +func (mr *MockActionAPIMockRecorder) Delete(id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockActionAPI)(nil).Delete), varargs...) +} + +// List mocks base method +func (m *MockActionAPI) List(opts ...management.RequestOption) (*management.ActionList, error) { + m.ctrl.T.Helper() + varargs := []interface{}{} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "List", varargs...) + ret0, _ := ret[0].(*management.ActionList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List +func (mr *MockActionAPIMockRecorder) List(opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockActionAPI)(nil).List), opts...) +} + +// MockActionVersionAPI is a mock of ActionVersionAPI interface +type MockActionVersionAPI struct { + ctrl *gomock.Controller + recorder *MockActionVersionAPIMockRecorder +} + +// MockActionVersionAPIMockRecorder is the mock recorder for MockActionVersionAPI +type MockActionVersionAPIMockRecorder struct { + mock *MockActionVersionAPI +} + +// NewMockActionVersionAPI creates a new mock instance +func NewMockActionVersionAPI(ctrl *gomock.Controller) *MockActionVersionAPI { + mock := &MockActionVersionAPI{ctrl: ctrl} + mock.recorder = &MockActionVersionAPIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockActionVersionAPI) EXPECT() *MockActionVersionAPIMockRecorder { + return m.recorder +} + +// Create mocks base method +func (m *MockActionVersionAPI) Create(actionID string, v *management.ActionVersion) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", actionID, v) + ret0, _ := ret[0].(error) + return ret0 +} + +// Create indicates an expected call of Create +func (mr *MockActionVersionAPIMockRecorder) Create(actionID, v interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockActionVersionAPI)(nil).Create), actionID, v) +} + +// Read mocks base method +func (m *MockActionVersionAPI) Read(actionID, id string) (*management.ActionVersion, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", actionID, id) + ret0, _ := ret[0].(*management.ActionVersion) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read +func (mr *MockActionVersionAPIMockRecorder) Read(actionID, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockActionVersionAPI)(nil).Read), actionID, id) +} + +// UpsertDraft mocks base method +func (m *MockActionVersionAPI) UpsertDraft(actionID string, v *management.ActionVersion) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpsertDraft", actionID, v) + ret0, _ := ret[0].(error) + return ret0 +} + +// UpsertDraft indicates an expected call of UpsertDraft +func (mr *MockActionVersionAPIMockRecorder) UpsertDraft(actionID, v interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsertDraft", reflect.TypeOf((*MockActionVersionAPI)(nil).UpsertDraft), actionID, v) +} + +// ReadDraft mocks base method +func (m *MockActionVersionAPI) ReadDraft(actionID string) (*management.ActionVersion, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ReadDraft", actionID) + ret0, _ := ret[0].(*management.ActionVersion) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ReadDraft indicates an expected call of ReadDraft +func (mr *MockActionVersionAPIMockRecorder) ReadDraft(actionID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadDraft", reflect.TypeOf((*MockActionVersionAPI)(nil).ReadDraft), actionID) +} + +// Delete mocks base method +func (m *MockActionVersionAPI) Delete(actionID, id string, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{actionID, id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Delete", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete +func (mr *MockActionVersionAPIMockRecorder) Delete(actionID, id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{actionID, id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockActionVersionAPI)(nil).Delete), varargs...) +} + +// List mocks base method +func (m *MockActionVersionAPI) List(actionID string, opts ...management.RequestOption) (*management.ActionVersionList, error) { + m.ctrl.T.Helper() + varargs := []interface{}{actionID} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "List", varargs...) + ret0, _ := ret[0].(*management.ActionVersionList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List +func (mr *MockActionVersionAPIMockRecorder) List(actionID interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{actionID}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockActionVersionAPI)(nil).List), varargs...) +} + +// Test mocks base method +func (m *MockActionVersionAPI) Test(actionID, id string, payload management.Object) (management.Object, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Test", actionID, id, payload) + ret0, _ := ret[0].(management.Object) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Test indicates an expected call of Test +func (mr *MockActionVersionAPIMockRecorder) Test(actionID, id, payload interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Test", reflect.TypeOf((*MockActionVersionAPI)(nil).Test), actionID, id, payload) +} + +// Deploy mocks base method +func (m *MockActionVersionAPI) Deploy(actionID, id string) (*management.ActionVersion, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Deploy", actionID, id) + ret0, _ := ret[0].(*management.ActionVersion) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Deploy indicates an expected call of Deploy +func (mr *MockActionVersionAPIMockRecorder) Deploy(actionID, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Deploy", reflect.TypeOf((*MockActionVersionAPI)(nil).Deploy), actionID, id) +} + +// MockActionBindingAPI is a mock of ActionBindingAPI interface +type MockActionBindingAPI struct { + ctrl *gomock.Controller + recorder *MockActionBindingAPIMockRecorder +} + +// MockActionBindingAPIMockRecorder is the mock recorder for MockActionBindingAPI +type MockActionBindingAPIMockRecorder struct { + mock *MockActionBindingAPI +} + +// NewMockActionBindingAPI creates a new mock instance +func NewMockActionBindingAPI(ctrl *gomock.Controller) *MockActionBindingAPI { + mock := &MockActionBindingAPI{ctrl: ctrl} + mock.recorder = &MockActionBindingAPIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockActionBindingAPI) EXPECT() *MockActionBindingAPIMockRecorder { + return m.recorder +} + +// Create mocks base method +func (m *MockActionBindingAPI) Create(triggerID management.TriggerID, action *management.Action) (*management.ActionBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", triggerID, action) + ret0, _ := ret[0].(*management.ActionBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create +func (mr *MockActionBindingAPIMockRecorder) Create(triggerID, action interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockActionBindingAPI)(nil).Create), triggerID, action) +} + +// List mocks base method +func (m *MockActionBindingAPI) List(triggerID management.TriggerID, opts ...management.RequestOption) (*management.ActionBindingList, error) { + m.ctrl.T.Helper() + varargs := []interface{}{triggerID} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "List", varargs...) + ret0, _ := ret[0].(*management.ActionBindingList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List +func (mr *MockActionBindingAPIMockRecorder) List(triggerID interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{triggerID}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockActionBindingAPI)(nil).List), varargs...) +} + +// Update mocks base method +func (m *MockActionBindingAPI) Update(triggerID management.TriggerID, v []*management.ActionBinding) (*management.ActionBindingList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", triggerID, v) + ret0, _ := ret[0].(*management.ActionBindingList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update +func (mr *MockActionBindingAPIMockRecorder) Update(triggerID, v interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockActionBindingAPI)(nil).Update), triggerID, v) +} + +// MockActionExecutionAPI is a mock of ActionExecutionAPI interface +type MockActionExecutionAPI struct { + ctrl *gomock.Controller + recorder *MockActionExecutionAPIMockRecorder +} + +// MockActionExecutionAPIMockRecorder is the mock recorder for MockActionExecutionAPI +type MockActionExecutionAPIMockRecorder struct { + mock *MockActionExecutionAPI +} + +// NewMockActionExecutionAPI creates a new mock instance +func NewMockActionExecutionAPI(ctrl *gomock.Controller) *MockActionExecutionAPI { + mock := &MockActionExecutionAPI{ctrl: ctrl} + mock.recorder = &MockActionExecutionAPIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockActionExecutionAPI) EXPECT() *MockActionExecutionAPIMockRecorder { + return m.recorder +} + +// Read mocks base method +func (m *MockActionExecutionAPI) Read(id string) (*management.ActionExecution, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", id) + ret0, _ := ret[0].(*management.ActionExecution) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read +func (mr *MockActionExecutionAPIMockRecorder) Read(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockActionExecutionAPI)(nil).Read), id) +} diff --git a/internal/auth0/rule_mock.go b/internal/auth0/rule_mock.go new file mode 100644 index 000000000..cdcaa3cc2 --- /dev/null +++ b/internal/auth0/rule_mock.go @@ -0,0 +1,130 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: rule.go + +// Package auth0 is a generated GoMock package. +package auth0 + +import ( + gomock "github.com/golang/mock/gomock" + management "gopkg.in/auth0.v5/management" + reflect "reflect" +) + +// MockRuleAPI is a mock of RuleAPI interface +type MockRuleAPI struct { + ctrl *gomock.Controller + recorder *MockRuleAPIMockRecorder +} + +// MockRuleAPIMockRecorder is the mock recorder for MockRuleAPI +type MockRuleAPIMockRecorder struct { + mock *MockRuleAPI +} + +// NewMockRuleAPI creates a new mock instance +func NewMockRuleAPI(ctrl *gomock.Controller) *MockRuleAPI { + mock := &MockRuleAPI{ctrl: ctrl} + mock.recorder = &MockRuleAPIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockRuleAPI) EXPECT() *MockRuleAPIMockRecorder { + return m.recorder +} + +// Create mocks base method +func (m *MockRuleAPI) Create(r *management.Rule, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{r} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Create", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Create indicates an expected call of Create +func (mr *MockRuleAPIMockRecorder) Create(r interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{r}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockRuleAPI)(nil).Create), varargs...) +} + +// Read mocks base method +func (m *MockRuleAPI) Read(id string, opts ...management.RequestOption) (*management.Rule, error) { + m.ctrl.T.Helper() + varargs := []interface{}{id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Read", varargs...) + ret0, _ := ret[0].(*management.Rule) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read +func (mr *MockRuleAPIMockRecorder) Read(id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockRuleAPI)(nil).Read), varargs...) +} + +// Update mocks base method +func (m *MockRuleAPI) Update(id string, r *management.Rule, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{id, r} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Update", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Update indicates an expected call of Update +func (mr *MockRuleAPIMockRecorder) Update(id, r interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{id, r}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockRuleAPI)(nil).Update), varargs...) +} + +// Delete mocks base method +func (m *MockRuleAPI) Delete(id string, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Delete", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete +func (mr *MockRuleAPIMockRecorder) Delete(id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockRuleAPI)(nil).Delete), varargs...) +} + +// List mocks base method +func (m *MockRuleAPI) List(opts ...management.RequestOption) (*management.RuleList, error) { + m.ctrl.T.Helper() + varargs := []interface{}{} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "List", varargs...) + ret0, _ := ret[0].(*management.RuleList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List +func (mr *MockRuleAPIMockRecorder) List(opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockRuleAPI)(nil).List), opts...) +} diff --git a/internal/cli/login.go b/internal/cli/login.go index 24f07ddb3..d578019ee 100644 --- a/internal/cli/login.go +++ b/internal/cli/login.go @@ -39,7 +39,7 @@ func RunLogin(ctx context.Context, cli *cli, expired bool) error { cli.renderer.Infof("If you don't have an account, please go to https://auth0.com/signup, otherwise continue in the browser.\n\n") } - a := &auth.Authenticator{Secrets: &auth.Keyring{}} + a := &auth.Authenticator{} state, err := a.Start(ctx) if err != nil { return fmt.Errorf("could not start the authentication process: %w.", err) @@ -63,6 +63,14 @@ func RunLogin(ctx context.Context, cli *cli, expired bool) error { cli.renderer.Infof("Successfully logged in.") cli.renderer.Infof("Tenant: %s\n", res.Tenant) + // store the refresh token + secretsStore := &auth.Keyring{} + err = secretsStore.Set(auth.SecretsNamespace, res.Tenant, res.RefreshToken) + if err != nil { + // log the error but move on + cli.renderer.Warnf("Could not store the refresh token locally, please expect to login again once your access token expired: %s.", err.Error()) + } + err = cli.addTenant(tenant{ Name: res.Tenant, Domain: res.Domain,