Auth0 Home Blog Docs

Programatically Login Javascript API Error


#1

Hi.
We’re trying to create a test application that will programmatically log in a couple of users.

We’re getting this error:

ReferenceError: window is not defined
    at Object.getWindow (/Users/me/SoftwareDev/shout-admin/node_modules/auth0-js/dist/auth0.min.js:8:40186)
    at Object.randomString (/Users/me/SoftwareDev/shout-admin/node_modules/auth0-js/dist/auth0.min.js:8:86524)
    at TransactionManager.generateTransaction (/Users/me/SoftwareDev/shout-admin/node_modules/auth0-js/dist/auth0.min.js:8:88775)
    at TransactionManager.process (/Users/me/SoftwareDev/shout-admin/node_modules/auth0-js/dist/auth0.min.js:8:88378)
    at WebAuth.login (/Users/me/SoftwareDev/shout-admin/node_modules/auth0-js/dist/auth0.min.js:8:122023)

We’re using the nodejs repository, and requiring it with

var auth0 = require("auth0-js");

Our code is

var webAuth = new auth0.WebAuth({
    domain: 'xxx.eu.auth0.com',
    clientID: 'xxxx',
    redirectUri: 'http://localhost:3333/mockUsers',
    responseType: 'token id_token'
});
    webAuth.login({
        realm: 'Username-Password-Authentication',
        username: 'bingo',
        password: 'xxxx',
        audience: 'https://api.xxx.io/'
    });

Additionally, once this is working, can we actually retrieve the token without redirecting to a new page?


#3

:wave: @shoutapp I may be misunderstanding but for your use case auth0-js is not intended to be used server side so if you just need to get tokens for the users we might want to use something like the the nodejs sdk http://auth0.github.io/node-auth0/module-auth.AuthenticationClient.html#passwordGrant
would this be what you are looking to do?