I’m trying to use MySQL SSL with a simple Javascript test application. I’m getting an error when I click the Try button to test my Auth0 custom code:
Invalid response code from the
auth0-sandbox: HTTP 400. Unexpected
token ;
I’m at a loss as to what it’s trying to tell me. It seems to be related to my use of “require(‘mysql@2.7.0’)” which I found referenced in another blog posting. Without this line of code, I get “ER_ACCESS_DENIED_ERROR: Access denied for user”. I have the MySQL server configured to require SSL on the login. I have verified using mysql at the CLI that I can connect to the database using SSL.
I’m new to Auth0 and I’m using the Javascript Quickstart:
https://auth0.com/docs/quickstart/spa/vanillajs/03-calling-an-api
I’m using Auth0 v8.7:
https://cdn.auth0.com/js/auth0/8.7/auth0.js
My custom database login script begins with:
require('mysql@2.7.0');
function login(email, password, callback) {
var connection = mysql({
host: configuration.DB_HOST,
user: configuration.DB_USER,
password: configuration.DB_PASS,
database: configuration.DB_NAME,
ssl: {
ca: configuration.DB_CA,
}
});
connection.connect();
The customs script you configured uses invalid syntax which leads to the error you mentioned.
If you want to require a specific node module to be used within the script you should do something similar to the following:
function login(email, password, callback) {
var mysql = require("mysql@2.7.0");
var connection = mysql({ /* ... */ });
// ...
}
Notice that the require
is performed within the custom script main function and the result is assigned to a variable so that it can later be used. You were doing a require outside the main custom script function and also not assigning the output which is invalid.
Thanks @jmangelo ! I changed my code to be:
var mysql = require(‘mysql@2.7.0’);
var connection = mysql.createConnection({
ssl: {
ca: configuration.DB_CA,
rejectUnauthorized: false
} … });
And now it works. I had to add the rejectUnauthorized because my server is using a self signed certificate for mysqld.
Thanks @jmangelo ! I changed my code to be:
var mysql = require(‘mysql@2.7.0’);
var connection = mysql.createConnection({
ssl: {
ca: configuration.DB_CA,
rejectUnauthorized: false
} … });
And now it works. I had to add the rejectUnauthorized because my server is using a self signed certificate for mysqld.