Passing context to the login script

I am using a custom database connection with a login script. During login, I need to know the source/referral url so i can identify the system the user belongs to. Is there a way to access the referral url? or context object in this method?

here is the signature of the login method

function login(email, password, callback) {
  // TODO: implement custom login
  return callback(null, profile);
}

Hi @utsab.lohani

There is not a way to do this.

What is the use case? Why do you need the referral URL? A connection shouldn’t require this to log a user in - only the credentials. If you need this, it is an indication the architecture isn’t right. If you provide more details I will try to help.

John

1 Like

Hi john

What if our external database needs a username[not email] and password for user authentication of user? for that, we need other attribute to be pass within login script. or take another scenario we want to get the user using a username in the get script. So how we can achieve it.

The login function will receive whatever the user entered in the login screen (email or username), so your code should detect if it’s an email (or username) and handle appropriately.

Thank you so much utsablohani for your response. I am using the custom database, where calling create user operation calls get, create and login script asynchronously. Now, the problem is my external DB use a username and password to authenticate the user. so, I can’t pass the username in the login script only email and password are available.

There is a switch to activate the context object for custom database scripts. But I’m only getting the realm name on it. I wonder why we can’t have access to request information like in actions

Hi @benjaminhonorio.12,

I see we both have the same issues @john.gateley we need your help. Lets suppose user have 3 attribute and username, email and password. Now get operation should able to get the user using username not by email. How to achieve that as well. The cause issues in login as well. When user try to create it will silently trigger the login script where it need username there as well, where it will pass that username in the login script as well. Is there any reference link where we can pass the parameter within the pre built template in those script?

I saw this for your use case, Adding Username for Database Connections but I´m not sure how you would access the other value if login only accepts one. I think username has precedence, check this auth0.js/index.js at 856d8cfd7d3c56ed7ac91e7a6955af2a0fc46b5e · auth0/auth0.js · GitHub

Hi @benjaminhonorio.12,

Thank you so much for your response. This is blocking my project, even in the get user script, I want to get the user based on the username. Is there is any implementation your reference please let me know?

I guess what I’m gonna tell you it’s not good but I figure I can append extra data to the password and then get it in the login script. So in your frontend you can just append whatever you want with pipes (|) for example, and once that piece of data arrives in the login script (as password argument) you just split it and use those values you appended, and retrieve the real password of course. It’s hacky but works.

Eaxactly, this is the only way left but is not good practice, As this has to be implement in the get user script as well. I want to get the user with username. I talk in another ticket and got a response that they have backlog item to address on this issues. You can check in the below item

1 Like

I see. Thanks for sharing. Good luck!

1 Like