Skip to content

Bare bones Node API for authenticating user credentials and JSON Web Tokens.

Notifications You must be signed in to change notification settings

trozdol/base-api-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BASE API AUTHENTICATION

Update config-mongodb.yml to point to where you want MongoDB to point.

storage:
    dbPath: "/path/to/mongo-auth"

Assuming MongoDB is installed locally...

mongod -f config-mongod.yml

Start the API Server:

npm install # if first time.

npm start

Should now be running on localhost:8080

Register:

POST: http://localhost:8080/api/register

curl \
-H "Content-Type: application/json" \
-X GET http://localhost:8080/api/login \
-d '{ "email": "[email protected]", "username": "examplename", "password": "123" }'

Full Example Body:

{
    "username": "yourhandle",
    "email": "[email protected]",
    "password": "123",
    "name": {
        "first": "John",
        "last": "Doe"
    }
}

Login:

POST: http://localhost:8080/api/login

curl \
-H "Content-Type: application/json" \
-X GET http://localhost:8080/api/login \
-d '{ "email": "[email protected]", "password": "123" }'

Example Response:

{
    "code": null,
    "message": "OK",
    "success": true,
    "data": [],
    "token": "xxx.yyy.zzz"
}

Authenticating Other Requests

curl \
-H "Content-Type: application/json" \
-H "Authorization: JWT xxx.yyy.zzz" \
-X GET http://localhost:8080/api/account

Headers:

"Authorization" : "JWT <token>"

Body: (needs some tweaks/coming soon)

{
    ...
    "token": "JWT <token>"
}

Query Param: (needs some tweaks/coming soon)

http://localhost:8080/api/account?token=<token>

About

Bare bones Node API for authenticating user credentials and JSON Web Tokens.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published