Coder Social home page Coder Social logo

andy-richardson / token-auth-service Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 34 KB

A microservice for session based authentication using JSON web tokens and Neo4j

License: MIT License

JavaScript 100.00%
nodejs neo4j microservice token-authetication

token-auth-service's Introduction

AUTHENTICATION MICROSERVICE

A microservice for session based authentication using JSON web tokens and a Neo4j database for session based management.

Intended usage

This service is intended to be accessed by the API to authenticate RESTless API requests. It is advised that you run this inside a docker container (or similar) to control access. Do not run this API publicly.

To effectively use this microservice, ensure your API does the following:

  • Call 'verify token' before allowing privileged API functionality

  • Check token expiry and 'PATCH' token if expiry date is nearing

  • Invalidate token when user logs out

User and session tracking

Users and sessions are stored in a Neo4j database. As of present, expired sessions are not automatically deleted from the database. Sessions have been abstracted from the API for simplicity. Tokens are seen as being either valid, invalid, blacklisted or expired.

Configuration

See private/config.js to configure JSON web token and Neo4j settings.

API FUNCTIONS

CREATE USER

Create a new user for authentication purposes.

Url

  • /auth/user

Method

  • POST

Parameters

Required

  • username=[String]

  • password=[String]

Success responses

  • Status: 201

  • Message: Success

Failure responses

  • Status: 400

  • Message: Username validation failed

or

  • Status: 400

  • Message: Password validation failed

or

  • Status: 409

  • Message: User already exists

or

  • Status: 500

  • Message: Unknown server error


CHANGE USER PASSWORD

Change the password of an existing user.

Url

  • /auth/user

Method

  • PATCH

Parameters

Required

  • username=[String]

  • password=[String]

Success responses

  • Status: 201

  • Message: Success

Failure responses

  • Status: 400

  • Message: Username validation failed

or

  • Status: 400

  • Message: Password validation failed

or

  • Status: 500

  • Message: Unknown server error


CREATE TOKEN

Validate user credentials and return token.

Url

  • /auth

Method

  • POST

Parameters

Required

  • username=[String]

  • password=[String]

Success Response

  • Status: 200

  • Message: Success

Failure responses

  • Status: 400

  • Message: User does not exist

or

  • Status: 401

  • Message: Bad credentials

or

  • Status: 500

  • Message: Unknown server error


VERIFY TOKEN

Verify token is valid and, if so, return username of token owner.

Url

  • /auth

Method

  • GET

Parameters

Required

  • token=[String]

Success Response

  • Status: 200

  • Username: [username]

Failure responses

  • Status: 400

  • Message: Token must be provided

or

  • Status: 400

  • Message: Token is invalid

or

  • Status: 401

  • Message: Token is expired

or

  • Status: 401

  • Message: Token is blacklisted

or

  • Status: 500

  • Message: Unknown server error


UPDATE TOKEN

Create new token from existing valid token

Url

  • /auth

Method

  • PATCH

Parameters

Required

  • token=[String]

Success Response

  • Status: 200

  • Token: [token string]

Failure responses

  • Status: 400

  • Message: Token must be provided

or

  • Status: 400

  • Message: Token is invalid

or

  • Status: 401

  • Message: Token is expired

or

  • Status: 401

  • Message: Token is blacklisted

or

  • Status: 500

  • Message: Unknown server error


INVALIDATE TOKEN

Blacklist token

Url

  • /auth

Method

  • DELETE

Parameters

Required

  • token=[String]

Success Response

  • Status: 200

  • Message: Success

Failure responses

  • Status: 400

  • Message: Token must be provided

or

  • Status: 400

  • Message: Token is invalid

or

  • Status: 401

  • Message: Token is expired

or

  • Status: 401

  • Message: Token is blacklisted

or

  • Status: 500

  • Message: Unknown server error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.