Giter Club home page Giter Club logo

bzz-angular's Introduction

bzz-angular

bzz-angular offers extensions to angular.js to interoperate with bzz.

Resources

  • AuthService provider: allows easy integration with bzz authentication api
  • AuthButton directive: allows easy login button implementation with default UI

Supported providers

  • GooglePlus
  • Facebook (still not implemented)
  • Github (still not implemented)
  • OAuth 2 (still not implemented)

Installing with bower

bower install --save bzz-angular

Configuring AuthService

First, add 'bzz.auth' on your module application's dependencies array:

var myModule = angular.module('myWebApp', [
  // ...
  'bzz.auth'
])

Then add AuthServiceProvider and angular $httpProvider as dependencies on the config step of your app:

myModule.config(function($routeProvider, /* ... */, $httpProvider, AuthServiceProvider) {
  // AuthServiceProvider configuration explained below...
})

On the routes you need authentication check, you need to to configure these routes with requiresAuthentication flag:

  $routeProvider.when('/needs-authentication', {
    controller: function() {},
    requiresAuthentication: true
  });

In the example above, the route /needs-authentication is configured with authentication check. This means that every time this route is changed to the current, a event to check authentication will be broadcasted to AuthService.

Still in the the config step, you need to configure the initialization vars for the service (the values below are the default ones). bzz-angular comes with sensible defaults, but you must configure the Client ID and Secret for the providers you want to use (in this example, Google). You must also configure the URL where bzz can be found:

  AuthServiceProvider.init({
    googleClientId: 'MYGOOGLECLIENTID'
    googleApiKey: 'MYGOOGLEAPIKEY'
    googleScopes: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
    bzzApiUrl: 'http://localhost:2368/'
    redirectWhenLogin: '/'
    loginPage: '/login'
  });

And add httpResponseInterceptor to the $httpProvider.responseInterceptors array:

  // This allows bzz-angular to make sure the user is authenticated in routes that require authentication.
  $httpProvider.responseInterceptors.push('httpResponseInterceptor')

Using the authentication service is as easy as using angular's dependency injection with:

myModule.run(function (AuthService) {});

The resulting code will looks like this:

angular.module('myWebApp', [
  // ...
  'bzz.auth'
]).config(function($routeProvider, /* ... */, $httpProvider, AuthServiceProvider) {
  $routeProvider.when('/needs-authentication', {
    controller: function() {},
    requiresAuthentication: true
  });
  // configuring
  AuthServiceProvider.init({
    googleClientId: 'MYGOOGLECLIENTID'
    googleApiKey: 'MYGOOGLEAPIKEY'
    googleScopes: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
    bzzApiUrl: 'http://localhost:2368/'
    redirectWhenLogin: '/'
    loginPage: '/login'
  });
  $httpProvider.responseInterceptors.push('httpResponseInterceptor');
}).run(function (AuthService) {});

Signals

A bzzUserSignedIn signal is broadcasted to Angular $rootScope every time a SignIn process is successful.

Also, a bzzUserSignedOut signal is broadcasted to Angular $rootScope every time a SignOut process occurs too.

So, to connect to these events, do:

  $rootScope.$on("bzzUserSignedIn", function() {
    console.log("Hey! I`m logged In");
    do_something();
  });
  $rootScope.$on("bzzUserSignedOut", function() {
    console.log("Hey! I`m logged Out");
    do_something_else();
  });

AuthButton Directive

bzz-angular comes with an auth-button directive. The goal is to make it simple to include authentication in your application. Just use in your templates:

  <auth-button provider="google"></auth-button>

bzz-angular's People

Contributors

ricardodani avatar heynemann avatar guilhermef avatar

Watchers

Rafael Floriano da Silva avatar  avatar Marcelo Jorge Vieira avatar James Cloos avatar Pablo Aguiar avatar

Forkers

ricardodani

bzz-angular's Issues

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.