Auth0 Home Blog Docs

How to manage redirection in code with auth0.js v9

hi,
I’m trying to authenticate user with auth0.js and redirect user to some custom URL
and followed the example on client.login(options, callback) , here is my codes look like :

var webauth = new auth0.Authentication({
  clientID: 'CLIENT_ID',
  domain: 'DOMAIN',
});
  webauth.login({
      realm: 'AUTH_DB_NAME',
      username: user_name,
      password: password,
      scope: 'read:order write:order',
  },function(err, authResult) { 
     if(authResult){
           redirectUser();
     }
  }); 

the code is submitting the requests but browser console shows https://test.eu.auth0.com/oauth/token responding with status 401

any help is appreciated , Thanks

Well already resolved the issue by adding the client_id,client_secret and grant_type property into login options and invoked the webauth.client.login(options, callback) method , now the updated code looks like this:

var webauth = new auth0.WebAuth({
   clientID: 'CLIENT_ID',
   domain: 'DOMAIN',
});


  webauth.client.login({
         realm: AUTH_DB_NAME,
         username: user_name,
         password: password,
         scope: 'read:order write:order',
         grant_type: 'http://auth0.com/oauth/grant-type/password-realm',
         client_id:CLIENT_ID,
         client_secret: CLIENT_SECRET
  },function(err, authResult) { 
       if(authResult){
              redirectUser();
      }
});

Glad you were able to make it and shared with the rest of community!

1 Like

@konrad.sopala thank you for your reply , could you please tell us why the github doc for client.login(options, callback) did not mention to put those properties : grant_type, client_id & client_secret ?

Hey @aminul!

I don’t have such knowledge. I think it will be best if you can reach out to repo maintainers via GitHub issue as they have most up to date knowledge about that.

1 Like

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