From lipp/login-with, adding POST /verify: Accept: { token: '' }, Return: { accessToken, profile }
499
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:
jwt - A "JSON Web Token" (JWT) containing profile information and the respective access tokens (Twitter/etc). http-only!profile - A JSON string which containing non-sensitive information (accessible from browser JS):
username - string / mandatory, the account specific user alias (e.g. Twitter name)photo - string / optional, the account specific user image linkname - string / optional, the "real" nameThe 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.
The configuration is done by means of environment variables.
LW_SESSION_SECRET - The session secret used by the microserviceLW_JWT_SECRET - The secret to sign the JSON Web Token (JWT)LW_SUBDOMAIN - The subdomain this microservice runs, e.g. login.yourdomain.com.
All other subdomains (e.g. api.yourdomain.com) and the top-level (e.g. yourdomain.com)LW_COOKIE_MAXAGE - The max age of the store cookie, defaults to 10 daysLW_PROFILE_COOKIENAME - The profile's cookie name, defaults to profileLW_JWT_COOKIENAME - The JSON Web Token's (JWT) cookie name, defaults to jwtLW_DYNAMIC_SCOPE - When set allows you to customize the scopes used in an authentication request, defaults to offYou 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
LW_GITHUB_CLIENTID - Your GitHub Client IDLW_GITHUB_CLIENTSECRET - Your GitHub Client SecretYou 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
LW_GOOGLE_CLIENTID - Your Google Client IDLW_GOOGLE_CLIENTSECRET - Your Google Client SecretYou 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
LW_FACEBOOK_APPID - Your Facebook App IDLW_FACEBOOK_APPSECRET - Your Facebook App SecretYou 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
LW_LINKEDIN_CLIENTID - Your Google Client IDLW_LINKEDIN_CLIENTSECRET - Your Google Client SecretYou need to create your own GitHub OAuth application. If LW_SUBDOMAIN=login.yourdomain.com your Authorization callback URL
must be: https://login.yourdomain.com/reddit/callback
LW_REDDIT_CLIENTID - Your Reddit Client IDLW_REDDIT_CLIENTSECRET - Your Reddit Client SecretYou 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
LW_TWITTER_CONSUMERKEY - Your Twitter Consumer KeyLW_TWITTER_CONSUMERSECRET - Your Twitter Consumer SecretYou 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
LW_MIXER_CLIENTID - Your Mixer Client IDLW_MIXER_CLIENTSECRET - Your Mixer Client SecretLW_MIXER_SCOPE - Specify which scopes the authorization request with Mixer should have. Check Mixer's documentation for scopes.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
LW_INSTAGRAM_CLIENTID - Your Instagram Client IDLW_INSTAGRAM_CLIENTSECRET - Your Instagram Client SecretYou 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
LW_STRAVA_CLIENTID - Your Strava Client IDLW_STRAVA_CLIENTSECRET - Your Strava Client Secret/twitter - login with Twitter account (if configured through env variables)/facebook - login with Facebook account (if configured through env variables)/github - login with GitHub account (if configured through env variables)/google - login with Google account (if configured through env variables)/reddit - login with Reddit account (if configured through env variables)/mixer - login with Mixer account (if configured through env variables)/linkedin - login with LinkedIn account (if configured through env variables)/instagram - login with Instagram account (if configured through env variables)/strava - login with Strava account (if configured through env variables)/logout - logout and clears the respective cookiesAll endpoints expect the query parameters:
success A url to redirect to in case of successful login (use encodeURIComponent for proper escaping)failure A url to redirect to in case of failed login (use encodeURIComponent for proper escaping)Don't forget to encodeURIComponent on them.
Say you deployed your login-with container with:
auth.your-domain.comThen 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.
Visit login-with.com. The source code is here.
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.
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
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 \
Content type
Image
Digest
Size
24.1 MB
Last updated
about 9 years ago
docker pull raohuaming/login-with