GithubHelp home page GithubHelp logo

waterlock / waterlock-facebook-auth Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 20.0 266 KB

Facebook authentication for waterlock

Home Page: http://waterlock.ninja/

License: MIT License

Makefile 6.12% JavaScript 93.88%

waterlock-facebook-auth's Introduction

Waterlock

Gitter

Inline docs

Build Status NPM version NPM downloads Dependency Status
Coverage Status Code Climate Gittip MIT License

Waterlock is an all encompassing user authentication/json web token management tool for Sails >= 0.10

What does it provide

Waterlock provides predefined routes and models for user authentication and json web token management. Password resets are also handled but we'll cover that below. Authentication is handled via methods. The current supported methods are:

Method Library
Local Auth waterlock-local-auth
Twitter Auth waterlock-twitter-auth
Facebook Auth waterlock-facebook-auth
Google Auth waterlock-google-auth

it is a great tool if you're looking to grant user access to your api.

How does it work

Since sails currently has no official support for 3rd party libraries like Rails gems; Waterlock works by hooking into your model and controller files adding the functionality needed. When Sails starts officially supporting 3rd party libraries this might change.

How do I use it

Glad you asked! If you're on a fresh install of a Sails app first run

npm install waterlock
npm install waterlock-local-auth

then run on mac/linux

./node_modules/.bin/waterlock generate all

or for windows

node_modules\.bin\waterlock generate all

this will generate all the necessary components, however you do not have strict access yet! The custom policies are generated via the command above but not yet applied. To apply policies crack open your config/policies.js file and add something like the following:

MyController:{
	'*': true,
	'myApiAction': ['hasJsonWebToken'],
	'mySessionAction': ['sessionAuth']
}

now with your policies applied to your custom controller you're good to go! (given you've actually implemented some login in them e.g. res.view())

How can I customize it?

Waterlock wraps around models and controllers so you can override any of the actions and definition that are predefined. After running waterlock generate all open up the User.js file you'll see this:

  attributes: require('waterlock').models.user.attributes({

    /* e.g.
    nickname: 'string'
    */

  }),

you can add any custom attributes you wish to your user model by just dropping them in like normal.

What if I want to control my own User model

Good question! If for whatever reason be it we haven't implemented a certain authentication method or your case it exceptionally complex. You can still take advantage of Waterlocks json web token management, so long as your user model has the following:

    jsonWebTokens: {
      collection: 'jwt',
      via: 'owner'
    },

this will keep the user association to the Jwt model and still allow for management of the tokens, which is what Waterlock tries to accomplish first and foremost.

Config

Waterlock generates a config located at config/waterlock.json this file is used to set various options

  • baseUrl - this is the URL your app resides at, used in password reset urls
  • autheMethod - the npm package name for the chosen authentication method or array of methods
  • jsonWebTokens - object containing information on how the jwt's should be constructed
    • secret - the secret used to encrypt the token, CHANGE THIS VALUE!
    • expiry - object containing information on expiry these are passed to moment.js add function
    • audience - the jwt aud claim a good choice is the name of your app
    • tokenProperty - customize the name of the property returning the token value
    • expiresProperty - customize the name of the property returning the expires value
    • includeUserInJwtResponse - when JWT is the default response for successful log-in you can return the user along with the token by setting this to true - cuts down round tripsg
    • subject - the jwt sub claim
  • postActions - lets waterlock know how to handle various login/logout events, you can read more about this in the docs

The Future

We would hope to turn this project into a well oiled jwt management tool for users.

Tests

Tests are run through the wonderful mocha so just clone the library run npm install then npm test

Feature Requests

I love to hear all of your feature requests, so if you have any please open an issue here! I'll be more than happy to work it into the roadmap if feasible.

Contributing

Feel free to contribute as you please, the more the merrier. Just please write test cases for everything you submit, in short you can follow the steps below. Happy coding! ๐Ÿ˜„

  1. Fork it ( http://github.com/waterlock/waterlock/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write test cases!
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

Legal Stuff

MIT (see License)

waterlock-facebook-auth's People

Contributors

duhruh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

waterlock-facebook-auth's Issues

User is registered twice

I am having a problem with facebook login as the user is registered as a new one again after registering the first time. When I looked at the database I found that the facebook Id is saved in a strange format -> '1.01568e16'. I think that when findOrCreate function is executed it doesn't find the Fb Id saved as retrieved from facebook so it registers a new one.

Another thing is that no attributes from facebook are saved 'email', 'first_name', etc. Please help.

Waterlock config:

fieldMap: {
// : ,
'firstName': 'first_name',
'lastName': 'last_name',
'gender': 'gender',
'timezone': 'timezone'
}

Home page video

Hi

Following the homepage tutorial video, when I get to the log in and go to /user/jwt I always get an unauthed response. I am logged in via postman and can see in the output "user login success" but going to /user/jwt doesn't work

I can get to /post/restricted however?

facebookId attribute too long for waterline integer

Hi,

I've been testing the waterlock facebook module and ran into some issues. This is not necessarily a problem with waterlock-facebook-auth.

The 17 digit facebookId is longer than the default allowed for type=integer using the waterline ORM (for mysql). The result is an incorrect store of the facebookId upon creation of a new user. The initial login and authentication is successful and an entry is created in the Auth table. However, upon logging out and logging back in, the authentication fails because the facebookId is not the correct 17 digit value (truncated as int(11) in mysql).

When using a local disk based storage, the full 17 digit facebookId is stored correctly and the problem does not occur. This is why testing on a default sails install does not reveal the issue. I have not tested on any other databases except mysql, but I suspect that a lack of support for larger integer types will be a problem as well.

My solution was to either:

  1. manually change the facebookId to bigint unsigned unique (20)
    OR
  2. change the auth attribute facebookId to type string -- varchar(255) unique in mysql.

For development purposes, I chose option 2 since we are constantly changing our models and need to drop the tables. I don't see any checks for int type or mathematical operations on the facebookId so this seems to work.

Performance differences between an int and varchar/char (unique and indexed) seems to be negligible even on millions of records so perhaps changing the facebookId attribute type to string for the facebook-auth module is the best way forward.

facebook fields such as 'email' doesn't return

var attr = {
facebookId: _data.id,
name: _data.name,
username: _data.name.replace(' ', ''),
email: _data.email
};
when make console.log(attr);
it return email null
please help
and thanks for your response :)

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.