And Why You Should Always Use Industry Standards In Your Apps
When computers were mostly standalone systems, authentication (checking people are who they say they are) and authorization (allowing them access to specific information) codes, along with databases containing user information, were self-contained on the device. Even in the early days of the web, sites would handle security independently, using custom and proprietary code.
Fast-forward to today and you can use the same login information across multiple apps and sites, either social logins or your custom enterprise login information for work. This is due to identity industry standards being widely employed across the web.
Identity industry standards are open specifications and protocols providing explicit guidance on how to design authentication and authorization systems to manage identity, move personal data securely, and decide who can access applications and data, so multiple parties can achieve interoperability easily.
The following are the Identity Industry Standards used by Auth0.
All of these standards are available in Auth0, and implementation requires little to no recoding as you move between different protocols or identity providers.
The easiest way to get started with standards is to implement the Open ID Connect / OAuth 2 login protocol, using JWT as the access token. This will allow your users or employees to login in easily with any social identity provider.
There are 6 steps to implementing this with Auth0:
http://www.yoursite.com/callback
<script src="https://cdn2.auth0.com/js/lock-8.2.min.js"></script> <script type="text/javascript"> var lock = new Auth0Lock('4CvZhjoDtdwciSPYLaby6EdJA6eBBRsi', 'username.auth0.com'); function signin() { lock.show({ callbackURL: 'http://www.yoursite.com/callback', responseType: 'code', authParams: { scope: 'openid profile' } }); } </script> <button onclick="window.signin();">Login</button>
GET
GET http://www.yoursite.com/callback?code=AUTHORIZATION_CODE&state=VALUE_THAT_SURVIVES_REDIRECTS
code
to the Auth0 server through a POST
POST https://username.auth0.com/oauth/token Content-type: application/x-www-form-urlencoded client_id=4CvZhjoDtdwciSPYLaby6EdJA6eBBRsi &redirect_uri=http://www.yoursite.com/callback &client_secret=4DxvHUwrabq6EQNe061PoFDeC5Ic5DamI2Eropuz-MLvi730WJijwZT6Zd6EM_nK &code=AUTHORIZATION_CODE &grant_type=authorization_code
{ "access_token":"2YotnF..........1zCsicMWpAA", "id_token": "......Json Web Token......", "token_type": "bearer" }
GET https://username.auth0.com/userinfo/?access_token=2YotnF..........1zCsicMWpAA
This will authenticate your users with their Open ID Connect identity provider, and pass back their normalized user profile for your application.
Implementing enterprise SSO is one of the easiest ways to take your SaaS upmarket and grow your revenue. Enabling enterprise clients to allow their employees to login to your application with their company details is likely a necessity for a potential enterprise customer to choose your SaaS.
Implementing SAML authentication in Auth0 is as easy as adding a few lines of code and adding your SAML identity provider information into the dashboard. The information you’ll need is:
This information can be added on the “SAML” configuration page under “Enterprise Connections”:
To use with Lock, you can add a few lines of code to redirect the Login and Logout functions to your SAML identity provider using an Express implementation, and including passport.js:
var express = require('express'); var router = express.Router(); var passport = require('passport'); /* GET users listing. */ router.get('/', function(req, res, next) { res.send(req.user); }); router.get('/authenticate', passport.authenticate('auth0', { failureRedirect: '/error' }), function(req, res) { if (!req.user) { throw new Error('user null'); } res.redirect("/"); }); router.get('/logout', function(req, res) { req.logout(); res.redirect("/"); }) module.exports = router;
You can learn more about this implementation by watching our video on switching to SAML.