Hello, I have a machine-to-machine app that creates new users in Auth0. And what I want to do is to create the user, then automatically log them in with the machine-to-machine app. Right now, they have to put in their Username and password on our registration app.
Then they are redirected to another auth0 app which is a regular web app with a universal login page from Auth0.
This is not a great user experience.
I know this is similar to this post silent-auto-login-for-user.
But this solution is for a regular web application. It’s also a .net/ c# app. I’m looking for a solution for a Python Django app which is machine-to-machine.
I use the Authorization API to get the token.
Then I use the token to make a call to Managment API to check to see if the user exists, if not, create the new user in Auth0
Creating the user gives me access to their Auth0 ID and their username/password so I have what I need to log them on.
And I don’t think that the Authentication API Login endpoint is what I’m looking for
https://auth0.com/docs/api/authentication#login
What are my options here. Any suggestions would be helpful. I am pretty new to this so it’s possible I overlooked the solution somewhere. Let me know if I have.
This is what my auth0 code looks like.
def create_auth0_user(self, password=None):
from auth0.v3.authentication import GetToken
from auth0.v3.management import Users
domain = 'mydomain.auth0.com'
ni_client_id = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
ni_client_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
get_token = GetToken(domain)
token = get_token.client_credentials(ni_client_id, ni_client_secret, 'https://{}/api/v2/'.format(domain))
mgmt_api_token = token['access_token']
users = Users(domain, mgmt_api_token)
# check if user exists
users_list = users.list(search_engine="v3", connection="PostgreSQL", q='email:"{}"'.format(self.app_object_entry.email))['users']
if len(users_list) > 0:
user = users_list[0]
users.update(id=user['user_id'], body={'password': self.__password__})
else:
# otherwise, create the new user in auth0.
u = users.create({
'connection': "PostgreSQL",
'email': self.myobject_entry.email,
'password': self.__password__,
'given_name': self.myobject_entry.first_name,
'family_name': self.myobject_entry.last_name,
})