npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

htauth

v1.0.0

Published

A simple Angular module to abstract Social Login (Facebook, Twitter, Google, ...)

Downloads

3

Readme

htauth

A simple Angular module to abstract Social Login (Facebook, Twitter, Google, ...)

To see the library in action use this JSFiddle Demo (but attention, facebook login inside jsfiddle environment doesn't work properly if you use chrome).

Available Providers

Planned Providers

  • Twitter (..future)

Install

You can install this package locally either with npm or bower

$ bower install htauth --save

$ npm instal htauth --save

You can also download and include the library file (full or minified) available in the /dist directory.

Usage

Facebook Login Provider

Full Example

angular
  .module('testapp', ['htauth'])
  .config(['htauth.facebookProvider', function(facebookProvider) {

    facebookProvider.init({
      appId: '174327009577654', //my app id
      locale: 'it_IT' // I'm a proud italian.
    })

  }])
  .controller('testFacebook', [
    'htauth.facebook',
    function(facebook) {
      // you can use:
      // facebook.login()
      // facebook.isLogged()
      // facebook.getAuthResponse()
      // facebook.getAccessToken()

      //NB: the provider automatically check if the user is already logged in your app
      // therefore a common flow may be

      //.. your code
        if(!facebook.isLogged())
          facebook.login().then(function(authResponse){
            // use authResponse.accessToken
          });
        else {
          // use facebook.getAuthResponse()
          // or simply facebook.getAccessToken()
        }
      //.. your code

    }
  ]);

Provider Configuration

Settings for provider configuration are described in Facebook Official Documentation (here and here).

facebookProvider.init(SettingsObject)
// Default settings are
{
  appId: false, // specify your APP ID
  cookie: true,
  locale: "en_US",
  status: true,
  version: "v2.5",
  xfbml: false,
  scope: "public_profile,email"
}
angular   // include htauth as dependecy
  .module('YourAPP', ['htauth'])
  .config(['htauth.facebookProvider', function(facebookProvider){

    // configure the facebookProvider with init settings
    // init settings are the same as Facebook Documentation
    // more info here: https://developers.facebook.com/docs/javascript/reference/FB.init/v2.5
    facebookProvider.init({
      appId : '174327009577654', // your app id
      locale: 'it_IT' // default locale is en_us
    })


  }])

Provider Instance API

facebook.login()

A Promise function that resolves when user correctly login to the App and reject if the user does not authorize your app or is not logged to facebbok.

angular   
  // ...something
  .controller('yourController', [
    'htauth.facebook',
    function(facebook) {

      //... code

      // open the facebook login modal
      // and get auth response as a promise
      facebook.login()
        .then(function(authResponse) {
          // user logged in, authResponse is
          // the object coming from Facebook

          // authResponse.accessToken may be useful

        })
        .catch(function(error) {
          // handle error;
        });

      //... code

      }

    }
  ]);

facebook.isLogged()

true if the user is logged in false otherwise

facebook.getAuthResponse()

get the AuthResponse Object coming from Facebook sdk (if the user is logged in)

facebook.getAccessToken()

get the accessToken (same as getAuthResponse().accessToken) if the user is logged in

Google Login Provider

Full Example

angular
  .module('testapp', ['htauth'])
  .config(['htauth.googleProvider', function(googleProvider) {

    googleProvider.init({
      client_id: '725412889739-g3iihggrd9ut7m9d8qhs65lal6k8v9q7.apps.googleusercontent.com' // my app id
    })

  }])
  .controller('testGoogle', [
    'htauth.google',
    function(google) {
      // you can use:
      // google.login()
      // google.isLogged()
      // google.getAuthResponse()
      // google.getIdToken()


      //NB: the provider automatically check if the user is already logged in your app
      // therefore a common flow may be

      //.. your code
        if(!google.isLogged())
          google.login().then(function(authResponse){
            // use authResponse (the same object coming from google APIS)
          });
        else {
          // use google.getAuthResponse()
          // or simply google.getIdToken()
        }
      //.. your code

    }  
  ]);

Provider Configuration

Settings for provider configuration are described in Google Official Documentation (here).

// Default settings are the same as Google init
{
  client_id: false, // specify your APP ID
  cookie_policy: 'single_host_origin',
  fetch_basic_profile: true, // scope is profile, email
  scope:  // optional if fetch_basic_profile is true
}
angular   // include htauth as dependecy
  .module('YourAPP', ['htauth'])
  .config(['htauth.googleProvider', function(googleProvider){

    // configure the googleProvider with init settings
    // init settings are the same as Google Documentation
    // more info here: https://developers.google.com/identity/sign-in/web/reference?hl=it#gapiauth2initwzxhzdk19paramswzxhzdk20)
    googleProvider.init({
      client_id: '725412889739-g3iihggrd9ut7m9d8qhs65lal6k8v9q7.apps.googleusercontent.com' // your app id here
    })


  }])

Provider Instance API

google.login()

A Promise function that resolves when user correctly login to the App and reject if the user does not authorize your app or is not logged to google.

angular   
  // ...something
  .controller('yourController', [
    'htauth.google',
    function(google) {

      //... code

      // open the facebook login modal
      // and get auth response as a promise
      google.login()
        .then(function(authResponse) {
          // user logged in, authResponse is
          // the object coming from Google

          // authResponse.id_token may be useful

        })
        .catch(function(error) {
          // handle error;
        });

      //... code

      }

    }
  ]);

google.isLogged()

true if the user is logged in false otherwise

google.getAuthResponse()

get the AuthResponse Object coming from Google sdk (if the user is logged in)

google.getIdToken()

get the id_token (same as getAuthResponse().id_token) if the user is logged in

Dev and Build

TODO

Test

TODO

License

MIT © Andrea Tarquini aka @h4t0n