trailsjs / sails-permissions

Comprehensive user permissions and entitlements system for sails.js and Waterline. Supports user authentication with passport.js, role-based permissioning, object ownership, and row-level security.
MIT License
418 stars 113 forks source link

Unknown policy, "basicauth" After Following Instructions #126

Open machineghost opened 8 years ago

machineghost commented 8 years ago

I tried to follow the instructions at:

https://www.npmjs.com/package/sails-auth

But when I tried to sails lift after following all of those steps the command failed, with the following error:

error: Unknown policy, "basicauth", referenced in `config.policies`.
error: Are you sure that policy exists?
error: It would be located at: `C:\Users\Me\WebstormProjects\proj\testProj\api\policies/basicauth.js`

Any ideas what I might have done wrong?

ryanwilliamquinn commented 8 years ago

@machineghost I just set up an example project to test it, and it worked fine. I'm using osx, sails version 0.12.0-rc3.

What does your api/policies/ folder look like?

machineghost commented 8 years ago

There's just one file in it, sessionAuth.js:

/**
 * sessionAuth
 *
 * @module      :: Policy
 * @description :: Simple policy to allow any authenticated user
 *                 Assumes that your login action in one of your controllers sets     `req.session.authenticated = true;`
 * @docs        :: http://sailsjs.org/#!/documentation/concepts/Policies
 *
 */
module.exports = function(req, res, next) {

  // User is allowed, proceed to the next policy, 
  // or if this is the last policy, the controller
  if (req.session.authenticated) {
    return next();
  }

  // User is not allowed
  // (default res.forbidden() behavior can be overridden in `config/403.js`)
  return res.forbidden('You are not permitted to perform this action.');
};
module.exports = function(req, res, next) {

  // User is allowed, proceed to the next policy, 
  // or if this is the last policy, the controller
  if (req.session.authenticated) {
    return next();
  }

  // User is not allowed
  // (default res.forbidden() behavior can be overridden in `config/403.js`)
  return res.forbidden('You are not permitted to perform this action.');
};
ryanwilliamquinn commented 8 years ago

which version of sails-permissions do you have installed? if it is in the 1.3 or 1.4 range i would expect more files than that there. i would try re-installing sails permissions in that case. what does your .sailsrc file look like?

machineghost commented 8 years ago

Re-installing sails-permissions fixed things! Thanks for the help.

EDIT I only sort of played with things after re-installing sails-permissions, and when I played some more I realized it hadn't actually fixed things. Not a big deal since this whole thing made me lose interest in Sails, but one more data point for everyone else with this problem. Sorry for the confusion.

ronky commented 8 years ago

Re-installing didn't help.

Tried:

Windows 8.1 x64 Sails 0.11.0 + Node 0.12.6 + Npm 2.11.2 + Sails Permissions 2.0.3 + Sails Auth 2.0.0-alpha2

Linux Mint 17.1 x64 Sails 0.11.0 + Node 0.10.37 + Npm 1.4.28 + Sails Permissions 2.0.3 + Sails Auth 2.0.0-alpha2

ronky commented 8 years ago

Tested again on linux mint 17.1 with newest node v0.12.7 and npm 2.11.3 and it still does not work.

Steps (all as root, I lost patience):

No policies, no models etc are under the API folder

Does it really work for anybody?

ayyappaappana commented 8 years ago

Yes @ronky

There is a problem with version 2.x with sails-permissions

Follow the steps but change sails-permissions with below line npm install sails-permissions@1.4.2 sails-auth --save

There is a version problem, expected should work with 1.4.2 version.

dbkaplun commented 8 years ago

+1, sails-permissions@2.1.3

See also #139

Rudy-Perrin commented 8 years ago

/generator.js has probably missing parameters. Someone can fix that ?

ifiokjr commented 8 years ago

I'm having this same problem with v2+ downgrading to 1.4.5 seems to be a current quick-fix.

ifiokjr commented 8 years ago

Okay so the problem seems to be version 2+ specific.

This commit removed a lot files from the /generator.js top level file.

The thing is I'm not 100% sure the reasoning behind the changes. Perhaps there are new ways of generating files that is meant to work in version 0.12+ (I'm using 0.11) for NodeJS 4.2.1 support. While Sails documentation is great in areas, it's not always clear on its roadmap or new features.

If anyone could point me in the right direction. I'd love to contribute a solution whether it's documentation on why things are being done the way they are, or a fix to ensure files are properly generated once more.

paulcitarella commented 8 years ago

+1 node 4.1.1, sails 0.11.2, sals-permissions 2.1.7. No policy files are being generated. Is anyone working on this?

delconis commented 8 years ago

The following is what works for me. "sails": "~0.11.0", "sails-auth": "^1.3.1", "sails-permissions": "^1.4.5"

It looks like marlinspike was not fully impmented in the commit mention above by @ifiokjr as a replacement for the current method.

You should be able to uncommit the lines from that commit for the generator.js. Or finish the implmention of marlinspike. I recommend finishing the implmention.

AlexisNo commented 8 years ago

I guess it will not be necessary to generate all these files with the next version of sails. The version 2 is probably ahead and should work with Sails' master branch.

ehsankhf commented 8 years ago

Thanks @AlexisNo

My sails configuration works well. The configuration is as follows:

"sails": "~0.12.0-rc3",
"sails-auth": "~2.1.1",
"sails-disk": "~0.10.7",
"sails-mongo": "^0.11.4",
"sails-permissions": "~2.1.8"
GeekLad commented 8 years ago

@ParanormalCoder I tried with that config on a new project, and it's not working for me.

ehsankhf commented 8 years ago

@GeekLad , thanks for feedback.

Well, you should have the same version of sails installed globally. So let's do as follows:

1- [type in console] sudo npm uninstall sails -g 2- [type in console] sudo npm install git://github.com/balderdashy/sails.git#master -g 3- Create your sails project, e.g. sails new mysails 4- add the following to your package.json file: ("dependencies" section) "sails-auth": "~2.1.1", "sails-permissions": "~2.1.11", 5- [type in console] cd mysails && npm install 6- follow the instruction on https://github.com/tjwebb/sails-permissions 7- if you miss installing any other modules (like lodash...), just install them

I just tested my solution, and it completely works in my computer. It has to work in your computer, as my instruction starts everything from the scratch (installing sails ...). If it does not work, it should be related to other things, not sails!

switchspan commented 8 years ago

@ParanormalCoder I just tried your above solution and it fixed the issue I was having. I think I had an older version of sails (~0.11.2). Everything is golden now...

yadavji83 commented 8 years ago

i have latest stable version sails 0.11.3, node 4.2.3 installed and its still not working. One thing i noticed is when we do: npm install sails-permissions --save it installs sails-auth 2.1.1, but if we do: npm install sails-auth --save it installs sails-auth 1.3.1 Don't know why this is happening.

This is very disappointing, i am trying to resolve it the whole day but no success

ehsankhf commented 8 years ago

@yadavji83 : Well, I've explained how to solve everything, step by step, in my previous/above post. Please read it!

yadavji83 commented 8 years ago

Yes i did that! I already had the latest version but still uninstalled it and followed you, but same error. Also i found some more issues, i posted this in chat window also:

i found that everywhere in your module you are assuming that sails-permissions is installed directly in the app directory, but this is not the case with my windows system. Its installed in npm-modules npm-modules folder so in sailsrc file it should be: "permissions-api": "node_modules/sails-permissions/generator" in permissions.js file it should be: var _super = require('../node_modules/sails-permissions/config/permissions'); i dont know if there are more issues coz i am still unable to make it work for me

ehsankhf commented 8 years ago

@yadavji83 Well, the sails-permissions does the loading of the config part automatically. Can you please share the "dependencies" section of your app's package.json?

yadavji83 commented 8 years ago

"basicauth": "0.0.1", "ejs": "~0.8.4", "grunt": "0.4.2", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-coffee": "~0.10.1", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-copy": "~0.5.0", "grunt-contrib-cssmin": "~0.9.0", "grunt-contrib-jst": "~0.6.0", "grunt-contrib-less": "0.11.1", "grunt-contrib-uglify": "~0.4.0", "grunt-contrib-watch": "~0.5.3", "grunt-sails-linker": "~0.9.5", "grunt-sync": "~0.0.4", "include-all": "~0.1.3", "rc": "~0.5.0", "sails": "~0.11.3", "sails-auth": "^1.3.1", "sails-disk": "~0.10.0", "sails-mysql": "^0.11.2", "sails-permissions": "^2.1.11"

also here sails-auth is 1.3.1 but the new version of sail-auth is installed inside sails-permissions i hope that has nothing to do with it

yadavji83 commented 8 years ago

I am quite sure that this has something to do with path because when i coped the policy files from sails-permission/api/policies folder to my app/api/policies folder the policy error resolved, but then it gives: cannot find modules fnv-plus: so i installed it and this error went off. sails is not finding the dependencies of sails-permissions in its folder rather its finding it in my app folder itself.

ehsankhf commented 8 years ago

@yadavji83 : You haven't done the 7 listed steps in my above instruction correctly! (postdate: 14 days ago)

your sails-permissions is OK, but the sails-auth is not ver. 2.1.1. Moreover, your sails itself is not the head master commit! So, these are the few issues I see!

So, try to read and follow that instruction carefully, step by step, again!

yadavji83 commented 8 years ago

Awwwwww!! It worked and i found my stupid mistake!

i tried it with sails@0.12.0-rc3 before and was not working either so i shifted to sails .11. The problem was as i mentioned before this command: install sails-permissions sails-auth --save

installs sails-auth1.3.1 and then sails-permissions install sails-auth-2.1.1, so i was "assuming" the later will be used, how stupid i am!!

A big thanks to @ParanormalCoder for your swift reply and patience. I know what you are thinking :)

yadavji83 commented 8 years ago

Also forgot to mention it will work with sails0.11 but you MUST change the sails-auth to v2.1.1 as @ParanormalCoder metioned.

yadavji83 commented 8 years ago

No its not working with sails0.11, many bugs come after you start using it, you should stick to the latest 0.12.0-rc3