satellizer

Project Logo

Satellizer

Build Status Code Climate Test Coverage Version

:space_invader: Live Demo: https://satellizer.herokuapp.com

Satellizer is a simple to use, end-to-end, token-based authentication module for AngularJS with built-in support for Google, Facebook, LinkedIn, Twitter authentication providers, plus Email and Password sign-in method. You are not limited to the sign-in options above, in fact you can add any OAuth 1.0 or OAuth 2.0 provider by passing provider-specific information during the configuration step.

Screenshot

Table of Contents

Installation

The easiest way to get Satellizer is by running one of the following commands:

Note: Alternatively, you may download the latest release or use the CDN:

Usage

Step 1. App Module ```js angular.module('MyApp', ['satellizer']) .config(function($authProvider) {

}); ```

Step 2. Controller ```js angular.module('MyApp') .controller('LoginCtrl', function($scope, $auth) {

}); ```

Step 3. Template html <button ng-click="authenticate('facebook')">Sign in with Facebook</button> <button ng-click="authenticate('google')">Sign in with Google</button> <button ng-click="authenticate('github')">Sign in with GitHub</button> <button ng-click="authenticate('linkedin')">Sign in with LinkedIn</button> <button ng-click="authenticate('twitter')">Sign in with Twitter</button> <button ng-click="authenticate('foursquare')">Sign in with Foursquare</button>

:exclamation: Note: For server-side usage please refer to the examples directory.

Configuration

Below is a complete listing of all default configuration options.

Browser Support

:exclamation: Note: If you stumble upon a browser version that does not work with Satellizer please open an issue so I could update the checkmark with the lowest supported version.

How It Works

Satellizer relies on token-based authentication using JSON Web Tokens instead of cookies. Each Wiki link below goes in-depth into how the authentication process works.

:bulb: Note: To learn more about JSON Web Token (JWT) visit JWT.io.

Obtaining OAuth Keys

- Visit Google Cloud Console - Click CREATE PROJECT button - Enter Project Name, then click CREATE - Then select APIs & auth from the sidebar and click on Credentials tab - Click CREATE NEW CLIENT ID button - Application Type: Web Application - Authorized Javascript origins: http://localhost:3000 - Authorized redirect URI: http://localhost:3000

:exclamation: Note: Make sure you have turned on Contacts API and Google+ API in the APIs tab.

- Visit Facebook Developers - Click Apps > Create a New App in the navigation bar - Enter Display Name, then choose a category, then click Create app - Click on Settings on the sidebar, then click + Add Platform - Select Website - Enter http://localhost:3000 for Site URL

- Sign in at https://dev.twitter.com - From the profile picture dropdown menu select My Applications - Click Create a new application - Enter your application name, website and description - For Callback URL: http://127.0.0.1:3000 - Go to Settings tab - Under Application Type select Read and Write access - Check the box Allow this application to be used to Sign in with Twitter - Click Update this Twitter's applications settings

API Reference

$auth.login(user)

Sign in via email and password where: - user - data object with email and password properties.

$auth.signup(user)

Creates a new local account where: - user - data object with email and password properties.

$auth.authenticate(name, [userData])

Starts the OAuth 1.0 or OAuth 2.0 authentication flow by opening a popup where: - name - one of the predefined provider names or a custom provider name created via $authProvider.oauth1() or $authProvider.oauth2(). - userData - optional object if you need to send some additional data to the server along with code, clientId and redirectUri in the case of OAuth 2.0 or oauth_token and oauth_verifier in the case of OAuth 1.0.

$auth.logout()

Logs out current user by deleting the token from Local Storage.

$auth.isAuthenticated()

Returns true or false depending on if the user is signed in or not.

Controller: js $scope.isAuthenticated = function() { return $auth.isAuthenticated(); };

Template: html <ul class="nav navbar-nav pull-right" ng-if="!isAuthenticated()"> <li><a href="/#/login">Login</a></li> <li><a href="/#/signup">Sign up</a></li> </ul> <ul class="nav navbar-nav pull-right" ng-if="isAuthenticated()"> <li><a href="/#/logout">Logout</a></li> </ul>

$auth.link(provider, [userData])

Links an OAuth provider to the account. Same as $auth.authenticate() with the exception that it does not redirect to $authProvider.loginRedirect path. - provider - one of the predefined provider names or a custom provider name created via $authProvider.oauth1() or $authProvider.oauth2(). - userData - optional object if you need to send some additional data to the server along with code, clientId and redirectUri in the case of OAuth 2.0 or oauth_token and oauth_verifier in the case of OAuth 1.0.

:bulb: Note: Account linking business logic is handled entirely on the server.

$auth.unlink(provider)

Unlinks an OAuth provider from the account by sending a GET request to the /auth/unlink/ URL.

TODO

  • [ ] C# (ASP.NET vNext) implementation
  • [ ] Elixir (Phoenix) implementation
  • [ ] Go (Beego) implementation
  • [x] Java (Dropwizard) implementation
  • [x] Node.js (Express) implementation
  • [x] PHP (Laravel) implementation
  • [x] Python (Flask) implementation
  • [ ] Ruby (Sinatra and/or Rails) implementation
  • [ ] Scala (Play!) implementation

Contributing

Found a typo or a bug? Send a pull request. I would especially appreciate pull requests for server-side examples since I do not have much experience with any of the languages on the TODO list.

Credits

A big thanks goes to Alice Chen for all your hard work on the Dropwizard implementation and Jesús Rodríguez for being so proactive and actively reporting bugs.

Additionally, I would like to thank all other contributors who have submitted issues and/or pull requests!

Satellizer was inspired by ng-token-auth and torii and angular-oauth.

License

The MIT License (MIT)

Copyright (c) 2014 Sahat Yalkabov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

comments powered by Disqus
This page was last updated over 2 years ago.