This is the sample application for Auth0's tutorial on doing authentication with observables. The app calls a NodeJS backend for public and private Chuck Norris quotes, all through the use of observables.
- Do
git submodule update --init
to pull the NodeJS API into theserver
directory cd
intoserver
and donpm install
- Run the Node server by doing
node server.js
cd
intoclient
and serve app with a local web server- Navigate to the app in your browser
In this example app, we create streams for nearly everything. We also create new streams from others and project values using map
and flatMap
.
var secretQuoteStream = secretQuoteClickStream
.map(function() {
var jwt = localStorage.getItem('id_token');
return {
url: 'http://localhost:3001/api/protected/random-quote',
jwt: jwt
}
});
We use the Fetch API for data retrieval and for POST
ing credentials to get a JWT back.
function getJwt(credentials) {
var config = {
method: 'POST',
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: credentials
}
return fetch('http://localhost:3001/sessions/create', config).then(function(data) {
return data.json().then(function(jwt) {
return jwt;
});
});
}
After all the streams are setup, we subscribe to them and observe the events that are emitted. We can do whatever we want with the emitted events, and for the case of the JWTs, we set them in local storage. For the retrieved quotes, we simply display them on the screen.
getJwtStream.subscribe(function(jwt) {
localStorage.setItem('id_token', jwt.id_token);
});
quoteResponseStream.subscribe(function(text) {
document.querySelector('.container h1').innerHTML = text;
});
Auth0 helps you to:
- Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others, or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider.
- Add authentication through more traditional username/password databases.
- Add support for linking different user accounts with the same user.
- Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
- Analytics of how, when and where users are logging in.
- Pull data from other sources and add it to the user profile, through JavaScript rules.
- Go to Auth0 and click Sign Up.
- Use Google, GitHub or Microsoft Account to login.
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
This project is licensed under the MIT license. See the LICENSE file for more info.