A Javascript RESTFUL API library for connecting with OAuth2 services, such as Google+ API, Facebook Graph and Windows Live Connect, complete with Angular.js support.
Angular.js or vanilla JS wrapper for https://adodson.com/hello.js/
Quick start shows you how to go from zero to loading in the name and picture of a user, like in the demo above.
- Register your app domain
- Include flybase-auth.js script
- Create the sign-in buttons
- Setup listener for login and retrieve user info
- Initiate the client_ids and all listeners
Register your application with at least one of the following networks. Ensure you register the correct domain as they can be quite picky.
<script src="https://cdn.flybase.io/flybase-auth.min.js"></script>
Just add onclick events to call flybaseauth(network).login()
.
<button onclick="flybaseauth('facebook').login()">Facebook</button>
Let's define a simple function, which will load a user profile into the page after they sign in and on subsequent page refreshes. Below is our event listener which will listen for a change in the authentication event and make an API call for data.
flybaseauth.on('auth.login', function(auth) {
// Call user information, for the given network
flybaseauth(auth.network).api('me').then(function(r) {
// Inject it into the container
var label = document.getElementById('profile_' + auth.network);
if (!label) {
label = document.createElement('div');
label.id = 'profile_' + auth.network;
document.getElementById('profile').appendChild(label);
}
label.innerHTML = '<img src="' + r.thumbnail + '" /> Hey ' + r.name;
});
});
Now let's wire it up with our registration detail obtained in step 1. By passing a [key:value, ...] list into the flybaseauth.init
function. e.g....
flybaseauth.init({
facebook: FACEBOOK_CLIENT_ID,
windows: WINDOWS_CLIENT_ID,
google: GOOGLE_CLIENT_ID
}, {redirect_uri: 'redirect.html'});
That's it. The code above actually powers the demo at the start so, no excuses.