Giter VIP home page Giter VIP logo

flybase-auth's Introduction

Flybase Auth

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

Quick start shows you how to go from zero to loading in the name and picture of a user, like in the demo above.

1. Register

Register your application with at least one of the following networks. Ensure you register the correct domain as they can be quite picky.

2. Include flybase-auth.js script in your page

<script src="https://cdn.flybase.io/flybase-auth.min.js"></script>

3. Create the sign-in buttons

Just add onclick events to call flybaseauth(network).login().

<button onclick="flybaseauth('facebook').login()">Facebook</button>

4. Add listeners for the user login

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;
	});
});

5. Configure flybase-auth with your client IDs and initiate all listeners

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.

flybase-auth's People

Contributors

freekrai avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.