API Login Without UI

What is a recommended way to do strictly API login (no UI) with credentials supplied in payload and retrieve an access_token back? The back-end could be a basic auth0’s managed Username-Password-Authentication DB, where username and password are stored. Please provide samples and auth’0 libraries in node if you have it.

Note: this is easily accomplished via UI (ie universal login) and tons of excellent guides, I have been searching community to this topic but I could not find a straight up resolution WITHOUT UI.

Thank you!

Hi @christian.suwiryo

There are two ways: ROPG and M2M

ROPG is Resource Owner Password Grant. It is NOT recommended, as you have to handle passwords in your app, instead of relying on the ULP for this, as well as losing SSO and centralization of IAM functionality. Docs are here:
https://auth0.com/docs/api/authentication#resource-owner-password
Again, this is NOT recommended.

The other way is client credentials or machine-to-machine. If the “user” is a server side application, this one is the way to go. Something like a cron job…

John

1 Like

Hi John, thanks for the info.

  • Noted that ROPG is NOT recommended, we do not plan to uptake / implement this.

  • We looked at the M2M prior to opening this ticket and was able to follow guides using the client_id and client_secret okay. However we need user context specific , we could not locate how to supply user context (username / password) in addition to client_id/secret in which API data response will be different contingent upon such user context. (it’s not a cron-job type.) Please let me know if we missed it, if so can you provide direct link to sample authenticating with client_id + client_secret + username (+ password [optional])? Please also advice different option if Client Credential or M2M did not support this.

Thank you!

1 Like

Hi @christian.suwiryo

There is no user context with client credentials. If the client credentials app has the user ID or email, you can give the app sufficient privileges to look up info on the user. Be aware that this means the client credentials app can look up info on ANY user.

If you truly need a “user context”, that is, if you really have a user logging in and need their profile, you’ll have to either use ROPG (not recommended) or a redirect flow like Auth Code or Auth Code + PKCE.

This use case is a bit confusing to me. An "API only " auth sounds like client credentials, but “users” sounds like there is a web app or native app to interact with. Which one is it?

John

1 Like

Hi John, noted with thanks.

To give you a bit more info:

  • We are able to use Auth0 web app login (universal) and native app login without problems. All customer facing apps that we have control are good.

  • There is however a third party tool which rely on a backend API to:
    (a) login with username/password in payload to retrieve access_token, and then
    (b) use the access_token to call various other protected APIs.
    We are trying to solve this use case, hence this post to the community channel.

Thanks again!

HI @christian.suwiryo

This use case is a third party app:

The third party app asks the user to log in via your Universal Login Page and gets an access token back.

John

2 Likes

Thank you John for your help. Much appreciated!!

We are here for you!

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