You typically don’t want to do this purely in JS, because keeping an Okta API token in the browser is very dangerous. The API token should only be used from backend code, because otherwise it would be trivial to steal.
The solution today is to write this code on your backend (in C#, or whatever language you’re using) and call it from the browser as needed.
Later on, we’ll be rolling out new features to the widget including the ability to register a new account. It’s not ready yet but that will make it easier to let users sign up, without having to write custom code.