lipp / login-with

Stateless login-with microservice for OAuth
https://login-with.com
MIT License
2.32k stars 143 forks source link
docker facebook google jwt linkedin login microservice now oauth passport reddit twitter

Build Status Coverage Status

About

Stateless authentication microservice for "login-with" functionality, supporting:

You can deploy with now or Docker (for mandatory and optional env variables see below).

$ now lipp/login-with
$ docker run lipp/login-with

This microservice must run in a subdomain of yours, e.g. login.yourdomain.com.

<a href='https://login.yourdomain.com/twitter?success=ON_SUCCESS_URL&failure=ON_FAILURE_URL'>
  Login with Twitter
</a>

On successful login two cookies will be created:

The cookies will be available for your toplevel domain and all subdomains. In addition, the cookie's secure flag is set, which means that your other websites/webservices must run over https.

Supported by

If you want to easily add token-based authentication to your apps, feel free to check out Auth0's SDKs and free plan at auth0.com/overview Auth0 logo.

Setup

The configuration is done by means of environment variables.

Mandatory environment variables

Optional environment variables

GitHub specific environment variables

You need to create your own GitHub OAuth application. If LW_SUBDOMAIN=login.yourdomain.com your Authorization callback URL must be: https://login.yourdomain.com/github/callback

Google specific environment variables

You need to create your own Google OAuth application. If LW_SUBDOMAIN=login.yourdomain.com your Authorization callback URL must be: https://login.yourdomain.com/google/callback

Facebook specific environment variables

You need to create your own Facebook login application. If LW_SUBDOMAIN=login.yourdomain.com your allowed redirects must be: https://login.yourdomain.com/facebook/callback

LinkedIn specific environment variables

You need to create your own LinkedIn OAuth2 application. If LW_SUBDOMAIN=login.yourdomain.com your Authorization callback URL must be: https://login.yourdomain.com/linkedin/callback

Reddit specific environment variables

You need to create your own Reddit OAuth application. If LW_SUBDOMAIN=login.yourdomain.com your Authorization callback URL must be: https://login.yourdomain.com/reddit/callback

Twitter specific environment variables

You need to create your own Twitter OAuth application. If LW_SUBDOMAIN=login.yourdomain.com your Authorization callback URL must be: https://login.yourdomain.com/twitter/callback

Mixer specific environment variables

You need to create your own Mixer OAuth Client. If LW_SUBDOMAIN=login.yourdomain.com your Authorization callback URL must be: https://login.yourdomain.com/mixer/callback

Instagram specific environment variables

You need to create your own Instagram OAuth application. If LW_SUBDOMAIN=login.yourdomain.com your Authorization callback URL must be: https://login.yourdomain.com/instagram/callback

Spotify specific environment variables

You need to create your own Spotify OAuth application. If LW_SUBDOMAIN=login.yourdomain.com is your Authorization callback URL must be: https://login.yourdomain.com/spotify/callback

Strava specific environment variables

You need to create your own Strava OAuth application. If LW_SUBDOMAIN=login.yourdomain.com your Authorization callback URL must be: https://login.yourdomain.com/strava/callback

AppleID specific environment variables

You need to be Apple Developer:

Endpoints

All endpoints expect the query parameters:

Don't forget to encodeURIComponent on them.

Testing

Say you deployed your login-with container with:

Then you can test everything by just "visiting" your login strategy with the browser, e.g. https://auth.your-domain.com/twitter. In case of success, you will be finally redirected and see the contents of your profile as JSON. In case of error, the error will be shown as JSON.

Example

Visit login-with.com. The source code is here.

Deployment with now

Note: You need a custom domain to run this microservice with now. Chrome (and maybe other browsers) explicitly prevent usage of wildcard cookies on .now.sh, which are required for this microservice to work.

  1. Create your secrets for the environment variables
  2. Deploy, e.g. with now
    now lipp/login-with \
    -e NODE_ENV=production \
    -e LW_SUBDOMAIN=login.yourdomain.com \
    -e LW_SESSION_SECRET=@lw-session-secret \
    -e LW_JWT_SECRET=@lw-token-secret \
    -e LW_REDDIT_CLIENTID=@lw-reddit-clientid \
    -e LW_REDDIT_CLIENTSECRET=@lw-reddit-clientsecret \
    -e LW_GITHUB_CLIENTID=@lw-github-clientid \
    -e LW_GITHUB_CLIENTSECRET=@lw-github-clientsecret \
    -e LW_TWITTER_CONSUMERKEY=@lw-twitter-consumerkey \
    -e LW_TWITTER_CONSUMERSECRET=@lw-twitter-consumersecret \
    -e LW_INSTAGRAM_CLIENTID=@lw-instagram-clientid \
    -e LW_INSTAGRAM_CLIENTSECRET=@lw-instagram-clientsecret \
    --alias login.yourdomain.com

Deployment with Docker

  1. Create your secrets for the environment variables
  2. Deploy, e.g. with Docker
    docker run lipp/login-with -p 80:3000 \
    -e NODE_ENV=production \
    -e LW_SUBDOMAIN=login.yourdomain.com \
    -e LW_SESSION_SECRET=@lw-session-secret \
    -e LW_JWT_SECRET=@lw-token-secret \
    -e LW_REDDIT_CLIENTID=@lw-reddit-clientid \
    -e LW_REDDIT_CLIENTSECRET=@lw-reddit-clientsecret \
    -e LW_GITHUB_CLIENTID=@lw-github-clientid \
    -e LW_GITHUB_CLIENTSECRET=@lw-github-clientsecret \
    -e LW_TWITTER_CONSUMERKEY=@lw-twitter-consumerkey \
    -e LW_TWITTER_CONSUMERSECRET=@lw-twitter-consumersecret \
    -e LW_INSTAGRAM_CLIENTID=@lw-instagram-clientid \
    -e LW_INSTAGRAM_CLIENTSECRET=@lw-instagram-clientsecret \