Giter VIP home page Giter VIP logo

authserver's Introduction

Auth Server

This is a simple Node / Express server with no UI. Its purpose is to isolate authentication / authorization functionality from the rest of a web app.

  • It is based on the authSandbox repo, found here.
  • It uses Passport JS's flash messaging functionality, and assumes you have flash message consumption in your app.
  • Use it by cloning this repo into the root of your project.
  • The code handles signing up, logging in and logging out. That's it. Right now it uses Passport JS, but in the future it might also use auth0.

It return a JWT upon successful registration / login.

Users can register a new account.

Users can log in in two different ways:

  • Basic Authentication (username / password)
  • OAuth2
    • Google
    • GitHub

A MongoDB / Mongoose database is used to save user info, and to persist authentication / session info. You can use a different database if you want to, but you will need to change code in the routes.

Technologies Used

  • Node / Express
    • bcrypt
    • express-session
    • express flash messaging
    • jsonwebtoken
  • MongoDB / Mongoose
    • connect-mongo
    • mongoose-find-or-create
  • Typescript
  • Passport JS
    • Basic authentication
    • OAuth2
      • Google
      • GitHub
    • JWT

Getting Started

After downloading / cloning the repo

npm install

You will need environment vars

AUTH_PORT=something.like.4500
SESSION_SECRET=put.your.session.secret.string.here
MONGO_CONNECTION_STRING=put.your.mongo.connection.string.here (eg: mongodb://localhost:27017)
AUTH_DATABASE_NAME=typcially.this.should.be.your.apps.name authService
COOKIE_MAX_AGE=in.total.milliseconds (eg: 1200000 = 20 mins.)

GOOGLE_CLIENT_ID=get.this.from.console.cloud.google.com
GOOGLE_CLIENT_SECRET=get.this.from.console.cloud.google.com
GOOGLE_REDIRECT_URL=something.like.http://localhost:4000/auth/google/redirect

GITHUB_CLIENT_ID=get.this.from.https://github.com/settings/application
GITHUB_CLIENT_SECRET=get.this.from.https://github.com/settings/application
GITHUB_REDIRECT_URL=something.like./auth/oauth/github/callback

JWT_TOKEN_SECRET=you.can.use.node.REPL.then.require('crypto').randomBytes(64).toString('hex') to make this

Run the server

npm run start

Once everything is installed and running, you can send your app's auth-related requests to this server.

Options

  • Basic Local
    • Username / Password
  • OAuth2
    • Google
    • GitHub
  • auth0
    • still researching this
  • JWT
    • For authorization / role / access level

Known Issues

  • Ssimultaneous OAuth2 authentication issue
    • Use Google, logout and the use GitHub
      • still logs in with Google

To Do

  • More Typescript
  • Research / implement auth0
  • Dockerize / Deploy
    • Netlify, et al.
    • Microservice / AWS
    • NPM package

authserver's People

Contributors

mattburnett-repo avatar

Watchers

 avatar

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.