Setup Auth0 with local database ran in a docker container - javascript

I've got a web-page at localhost:8080 with a login button that triggers a call to the auth0 handler. It works fine as long as it interacts with their database. Now i'm trying to set-up my own database, but can't seem to fill correctly the login script.
My database runs through a docker container via the command-line:
docker run —ip="172.0.0.3" —net="unihub-network" -p 13306:3306 -e MYSQL_ROOT_PASSWORD=mypasswd -d unihub-mysql
Using their template, I wrote:
function login(email, password, callback) {
var connection = mysql({
host: 'my-ip-address',
user: 'my-user',
password: 'my-psw',
database: 'UNIHUB_DB' //supposed to be the name of my db
});
Which obviously doesn't work. I can access my DB through software like SQuirreL at jdbc:mysql://localhost:13306/UNIHUB_DB, but it looks like i would need to access it through a URL to put in the login script for auth0.
Any thought on this ?

Related

Postgresql Difficulties on open a backup

I have an app with Node.JS where I have Sequelize to manage my database created in Postegresql on my vps.
I'm trying to backup the database with the command:
pg_dump dbname -U user -h 127.0.0.1 -f > db.sql
Then it asks the password that, in my case, I have set on Sequelize on the app and it creates a backup.
But when I try to open it on my pc, for exemple in DB Browser, it asks the key where I insert the password for the database, the user password for psql (which is the same) and the vps password but nothing happens. It does not open the database. What am I doing wrong?
In order to create user and database on psql I used this guide: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04
Thank you

How can I set database authentication in Mongodb - Is SSH Pipes better for MongoDB?

I have installed MongoDB in my computer. I did't define any password and username for the installation. I can see everything with Robo 3T.
Now I want to protect my database.
I have tried to set authentication for the database. I followed https://docs.mongodb.com/manual/tutorial/enable-authentication/ . It did not work.
I still can reach mongodb with robo 3t and see all information.
I have also tried to start mongodb with --auth parameter. I have define a configuration file looks like
And for starting mongodb
mongod -f C:\mongodb\conf\mongodb.conf
Mongodb has been started but, it did not ask any pass. And I can save simple data with Postman without authentication.
What I want to do:
Protect my database against Robo 3t. :))
I dont want to save any data without auth.
Building Nodejs connection string that include pass like
mysql://root:password#localhost:port/dbName
Here is my Nodejs index.js code
this is my model.
PS: I am very new in Nodejs and Mongodb.
EDIT: inside conf file

Deployed database has no connections

I have deployed an application to heroku: https://stark-citadel-91743.herokuapp.com/
The app initially loads properly until you click a button that requires the database. Then it crashes.
Everything works in local development environment. I believe I have properly set up all connection settings for production in heroku dashboard's config variables (database url, database name, username, password). But in production it doesn't work.
Two evidences that it's not set up right:
1) When I log into the ClearDB MySQL plugin (in my heroku dashboard) under 'current connections' it says, 'No connections are currently established to the database.'
2) When I use postman to hit a custom endpoint I made just for testing a request to the database, I get: "Error adding color: Error: connect ECONNREFUSED 127.0.0.1:3306" <-- that 127.0.0.1 seems enlightening. Why would a deployed db have a connection on that address?
Any clues? Thank you!
If your database is also set up at keroku host:
check the db setting(username, pw, port,etc.)
If you actually need to connect back to your own database(which is hosted by you or other third party);
You should find out the setting and replace with 127.0.0.1:3306, which is only work for local env
Update:
127.0.0.1 is localhost, which is your machine. Your test case is working because your server and your database are hosting on the same machine(which both have same ip). However, when your code are deployed to heroku, your heroku server cannot find a database hosted on same machine. This is why your are having this problem

MongoDB Cloud9 Connection

So, I am wondering if there is a way to connect to the mongoDB I have setup in my Cloud9 from an html. I mean, I have already connected to the db from the terminal and everything is working like a charm but I need to do some stuff inside my script in an html document and when I try calling the function which contains this code it does nothing
var MongoClient = require('mongodb').MongoClient
, format = require('util').format;
MongoClient.connect('mongodb://127.0.0.1:27017/ingesoft', function (err, db) {
if (err) {
throw err;
} else {
console.log("successfully connected to the database");
}
db.close();
});
I have saved the same code into a "file.js" and ran it from console using node file.js and it outputs into the console log "successfully connected to the database", plus the terminal which is running mongo's connection shows me one more connection to the db. The thing is, when I try to run that code inside my script it doesn't work. Sorry for my ignorance I am new to mongo.
Any help would be much appreciated
To simplify your question, here's what's going on:
node file.js containing the code in your question is working
pasting the same code to your html file is not
So, getting to the bottom of the issue, let's ask first: what's the difference between running node file.js and putting the code in html?
The difference is that node ... is running on your Cloud9 workspace (let's call it the server machine).
Your MongoDB server is also running on that server machine
The mongodb npm package you installed is also present on the server machine
The url: mongodb://127.0.0.1:27017/ingesoft references 127.0.0.1 which is the localhost for your server
whereas with the code on your browser:
The code is being run on your customer's machine
That machine doesn't have your Mongodb server
Browser's usually don't support require
You can do requires if you bundle code and use something like webpack or browserify. Did you perhaps do that?
If you did indeed package everything, was the mongodb package that you're requiring packaged?
Can the mongodb package be run from the client side?
The url: mongodb://127.0.0.1:27017/ingesoft references 127.0.0.1 which is the localhost for your customer's machine
Basically, as you can see from the above, the two are very different.
If you want to talk to your db, a lot of people go the following route:
Make a server application that implements some form of REST API
That REST API talks to your DB
Your client code knows how to talk to the REST API and get the required data
That way, you only talk to your MongoDB using your server, and the client can talk to your server via the internet.
This is, of course, an oversimplification, but I hope this resolves your confusion.

Meteor.js + external Mongo. Meteor cannot login into Mongo

I have a meteor.js app + mongo db (2.6).
I've created a user in mongo like this:
use meteor
db.createUser(
{
user: "meteor",
pwd: "password",
roles:
[
{
role: "userAdmin",
db: "meteor"
}
]
}
)
here is my mongodb.conf:
dbpath=/data/db
logpath=/var/log/mongodb/mongodb.log
logappend=true
port = 27017
when i set auth = true then my meteor app cannot connect to mongo anymore. It says
Exception in callback of async function: MongoError: auth failed
Same error when i try to connect with RoboMongo when auth is true. When auth is false i can connect with RoboMongo. So it's not about Firewall or something.
I don't understand, what I can do to switch on authorization in Mongo, so that it would let me login. Please help.
It depends on how you start Meteor. You need to tell it which Mongo instance to use and also provide proper credentials like this:
export MONGO_URL=mongodb://<username>:<password>#<host>:<port>/<db>
That's the way I've been doing it with my Meteor apps and a dedicated MongoDB and it works nicely. But if RoboMongo is not able to connect, there may be something wrong with the Mongo configuration. You can use this command to enable authentication in your config:
mongod --auth --config /path/to/mongodb.conf
I assume you have an admin user already which was used to create the meteor user, you will run into issues if you start Mongo without authentication, then add a meteor user anonymously and restart with auth=true.

Categories

Resources