Auth0 Home Blog Docs

How can I script using Python/Ruby to get a full IdToken

jwt
ruby
script
automated

#1

I need to accomplish a login flow to get a full IdToken, but not from my app but from a script instead. I tried looking at the API Authentication but couldn’t get it done. Could you please provide some help on how to script using any language ?


#2

Hi @systems1

If you want to get a valid, current ID token for a user from one of your Applications, probably the easiest way to do that is a password grant. In short, POST a JSON body like:

{
  "grant_type": "password",
  "scope" : "openid",
  "username": "REPLACE_WITH_EXISTING_USERNAME",
  "password": "REPLACE_WITH_EXISTING_PASSWORD",
  "client_id": "REPLACE_WITH_EXISTING_CLIENT_ID",
  "client_secret": "REPLACE_WITH_EXISTING_CLIENT_SECRET"
}

… to https://YOUR-TENANT.auth0.com/oauth/token and you should get a JSON response with an id_token key. This is using an existing database connection user in Auth0 for an Application that uses that same connection, just to be clear. If you’re implementing this into an application, there are additional security considerations but, as a local command line or script test, this should work fine.

More info on the Authentication API docs as well.