- Code developed for academic purposes.
- User management CRUD API with express.
- Clone the repository :
git clone https://github.com/JrSchmidtt/api-express-user-auth
- Install node.js to run
- Install Visual Studio Code to edit
- Install HeidiSQL and import database.sql
- Open the powershell Terminal in Visual studio and run the command
npm install
in folder to install the dependencies - Run the command
node index.js
in the folder with the usage examples
Returns the list of all registered users only for authenticated administrators.
var request = require('request');
var options = {
'method': 'GET',
'url': 'http://localhost:8080/user',
'headers': {
'Authorization': 'Bearer AUTHENTICATED-ADMIN-ACCOUNT-TOKEN'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
[
{
"id": 19,
"name": "Dixie",
"email": "dfurber4@sakura.ne.jp",
"role": 0
},
{
"id": 25,
"name": "admin",
"email": "admin@server.com",
"role": 1
}
]
Returns information of a specific account.
var request = require('request');
var options = {
var request = require('request');
var options = {
'method': 'GET',
'url': 'http://localhost:8080/user/25',
'headers': {'Authorization': 'Bearer AUTHENTICATED-ADMIN-ACCOUNT-TOKEN',}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
{
"id": 25,
"email": "admin@server.com",
"role": 1,
"name": "admin"
}
Create a new user account.
var request = require('request');
var options = {
'method': 'POST',
'url': 'http://localhost:8080/user',
'headers': {
'Authorization': 'Bearer AUTHENTICATED-ADMIN-ACCOUNT-TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"email": "admin@server.com",
"name": "admin",
"password": "0808",
"role": "1"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
{
"status": "200",
"desc": "User has been created",
"user": "admin",
"email": "admin@server.com"
}
Create an admin authorized token.
var request = require('request');
var options = {
'method': 'POST',
'url': 'http://localhost:8080/login',
'headers': {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"email": "admin@server.com",
"password": "SUPER-SECURE-PASSWORD"})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFkbWluQHNlcnZlci"
}
Generate a password reset token.
var request = require('request');
var options = {
'method': 'POST',
'url': 'http://localhost:8080/recoverPassword',
'headers': {
'Authorization': 'Bearer AUTHENTICATED-ADMIN-ACCOUNT-TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"token": "username@server.com"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
{
"status": "200",
"desc": "Recover Token has been created",
"token": "dc907a89-9097-47c1-b951-3f64244ff59a",
}
Change an account password.
var request = require('request');
var options = {
'method': 'POST',
'url': 'http://localhost:8080/changePassword',
'headers': {
'Authorization': 'Bearer AUTHENTICATED-ADMIN-ACCOUNT-TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"token": "9f97107e-d048-4c10-9c1a-60f09d2ca008",
"password": "NEW-PASSWORD"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
{
"status": "200",
"desc": "Password updated"
}
Update account information.
var request = require('request');
var options = {
'method': 'POST',
'url': 'http://localhost:8080/user/25',
'headers': {
'Authorization': 'Bearer AUTHENTICATED-ADMIN-ACCOUNT-TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"name": "New Name",
"email": "new@email.com",
"role": "1"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
{
"status": "200",
"user": "25",
"desc": "has been updated"
}
Delete the account passed to the backend.
var request = require('request');
var options = {
'method': 'DELETE',
'url': 'http://localhost:8080/user/9',
'headers': {
'Authorization': 'Bearer AUTHENTICATED-ADMIN-ACCOUNT-TOKEN'}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
{
"status": "200",
"user": "17",
"desc": "has been deleted"
}
- Fork the repository!
- Clone your fork:
git clone https://github.com/JrSchmidtt/api-express-user-auth
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Api User Auth © JrSchmidt.
Authored and maintained by Schmidt#9639.