Skip to content

Commit

Permalink
fix: ListUsers (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
notdodo authored Feb 10, 2024
1 parent 05f7f5d commit 89ff51c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/infra/okta/okta_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,43 @@ type OktaClient interface {
type oktaClient struct {
oktaClient *okta.Client
log logging.LogManager
ctx context.Context
}

func NewOktaClient(orgUrl, apiKey string) OktaClient {
logger := logging.GetLogManager()
_, client, err := okta.NewClient(context.TODO(), okta.WithOrgUrl(fmt.Sprintf("https://%s", orgUrl)), okta.WithToken(apiKey))
ctx, client, err := okta.NewClient(context.TODO(), okta.WithOrgUrl(fmt.Sprintf("https://%s", orgUrl)), okta.WithToken(apiKey))
if err != nil {
logger.Error("Invalid Okta login", "err", err)
}
logger.Info("Valid Okta client", "org_url", orgUrl)
return &oktaClient{
oktaClient: client,
log: logger,
ctx: ctx,
}
}

func (c *oktaClient) Users() ([]*okta.User, error) {
c.log.Info("Getting Okta users")
var users []*okta.User
appendUsers := func(oktaUsers []*okta.User) {
users = append(users, oktaUsers...)
}

oktaUsers, response, err := c.oktaClient.User.ListUsers(context.TODO(), nil)
if err != nil {
return nil, err
}
appendUsers(oktaUsers)
users = append(users, oktaUsers...)
for response.HasNextPage() {
var oktaUsers []*okta.User
response, err = response.Next(context.TODO(), &oktaUsers)
if err != nil {
return nil, err
}
appendUsers(oktaUsers)
users = append(users, oktaUsers...)
}

c.log.Info(fmt.Sprintf("Found %d users", len(users)))
c.log.Debug(fmt.Sprintf("Found %d users", len(users)), "users", response.Body)
c.log.Debug(fmt.Sprintf("Found %d users", len(users)), "users", users)
return users, nil
}

Expand Down

0 comments on commit 89ff51c

Please sign in to comment.