@articulate/okta-profile-monitor

Small library for monitoring for user creation or user profile changes in Okta and retreiving the user's current profile data after the change.

Usage no npm install needed!

<script type="module">
  import articulateOktaProfileMonitor from 'https://cdn.skypack.dev/@articulate/okta-profile-monitor';
</script>

README

okta-profile-monitor

Small library for monitoring for user creation or user profile changes in Okta and retreiving the user's current profile data after the change.

Usage

Works by checking an S3 bucket for the current Okta log URL to query, returning up to 1000 results from Okta.

monitor

Returns a "monitor" object that will pull profile and/or group events from the system log. These events can be consumed all at once as a Promise or individually as a stream.

const { monitor } = require('@articulate/okta-profile-monitor')

const oktaToken = 'myToken'
const oktaUri = 'https://mydemo.oktapreview.com'
const bucketParams = {
  Bucket: 'myBucket',
  Key: `path/nextLogUrl.txt`,
}

const m = monitor(oktaToken, oktaUri, bucketParams, {
  groups: true,
  profiles: true,
})

Consume the events with one of the following:

m
  .promise()
  .then(messages => console.log(`Do stuff with ${messages}`))
  .catch(err => console.error('handle error', err))
  .finally(m.close)

Or

const s = m.stream()
s.on('data', message => console.log(`Do stuff with one ${message}`))
s.on('error', err => console.error('handle error', err))
s.on('end', m.close)

Params

Name Type Description Required
oktaToken String API Token for Okta's API
oktaUri String Base URL for your Okta Account
bucketParams Object AWS S3 bucket parameters to read & update the url of the next page of logs
options Options Other options

Options

Name Type Description Default
sessions Boolean If true, capture user session events: user.session.start false
deletes Boolean If true, capture user deleted events: user.lifecycle.delete.initiated false
groups Boolean If true, capture group & group membership events: group.lifecycle.create, group.lifecycle.delete, group.user_membership.add, & group.user_membership.remove. false
profiles Boolean If true, capture user profile events: user.account.update_profile, user.lifecycle.activate, user.lifecycle.create, user.lifecycle.deactivate, user.lifecycle.suspect, & user.lifecycle.unsuspend true

Returns

A "monitor" object.

Method Return Type Description
promise Promise [Object] Returns a Promise of all events. Will reject if any errors are encountered.
stream Readable Object Returns a Readable stream in object mode. Will emit each event. If errors are encountered, will emit an error event.
close Marks the page of logs as finished. Saves the URL of the next page of logs to S3. Must be called on success.

Also implements EventEmitter. Emits the following events.

Event Parameters Descrition
apicall (String description) Emitted whenever an API call is made to Okta.

main

Deprecated

Consume all profile events & pass to a callback. Functionally equivalent to calling monitor with the profile: true option.

const { main } = require('@articulate/okta-profile-monitor')

const oktaToken = 'myToken'
const oktaUri = 'https://mydemo.oktapreview.com'
const bucketParams = {
  Bucket: 'myBucket',
  Key: `path/nextLogUrl.txt`,
}

const myCallback = messages =>
  console.log(`Do stuff with ${messages}`)

main(bucketParams, oktaUri, oktaToken, myCallback)