Force log-in users to using API

I am using Keycloak for user login. Is there a way to do this using the API?

You can generate a resume token.

Check this endpoint for more information:

My Django server takes a Keycloak user request and creates a direct message. If the user is not created in Rocket Chat, then an error appears:

Python request:

direct_message = settings.ROCKET_CHAT.im_create(username='alex123').json()


{'success': False, 'error': 'Invalid user [error-invalid-user]', 'errorType': 'error-invalid-user', 'details': {'method': 'createDirectMessage'}}

Since the user is not in the Rocket chat database, I need to force login to Rocket Chat via Keycloak using the API

Oh, I see.

Your problem is not login.

Your problem is that the user doesn’t exist, so it cannot create the direct room without an existing user.

Not sure what you want to accomplish, but you should consider another approach.

You will not be able to send a direct to a non existing user, and also, you will not be able to force the user creation, as it will depend on the Keycloack machinery to validate it.

One approach would be to send a message from Django using celery, for example, as a task (I love Django, by the way!!), and make it resilient enough to keep trying until the user is created or reschedule it for later after X tries.

let me know if that helps