Securing a node CLI with auth0

I’m a little lost trying to get a CLI I’m developing to be a client for auth0. I have auth0 set up with a database connection and users and an oclif based node.js CLI application. I’d like to prompt users to login and then use the token I recieve to send to our web services. I pulled auth0-js from npm which we use on our web site. WebAuth is browser only and I can’t instansiate Authentication directly as it doesn’t have a login method that takes the same email/password credentials. Am I barking up the wrong tree?

Hi @piers

Since you’re using node.js you want to use the node-auth0 library instead of the auth0-js library.

With this library you can use the Database Authenticator to login using username / password combo (relevant docs).

Hope this helps!

1 Like

I’ve done that but now when I use the signIn method:

await this.authClient.database!.signIn({
username: email,
password,
connection: ‘Username-Password-Authentication’,
})

I get back a token which doesn’t contain the custom data I added via a rule.

But when I use a password grant:

const asd = await this.authClient.oauth!.passwordGrant({username: email, password, realm: 'Username-Password-Authentication'})
I’m not sure I understand the difference.

Hi @piers

Sorry for the late response, work commitments and public holidays got in the way :slight_smile:

You are correct in using this.authClient.oauth!.passwordGrant instead of this.authClient.database!.signIn.

The reason for this is that the passwordGrant method uses a newer endpoint while the signIn method uses an older deprecated endpoint.

Hope this helps!

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.