Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/1602/compound-passport
PassportJS integrated with Compound
https://github.com/1602/compound-passport
Last synced: 19 days ago
JSON representation
PassportJS integrated with Compound
- Host: GitHub
- URL: https://github.com/1602/compound-passport
- Owner: 1602
- Created: 2012-03-04T15:27:28.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2016-11-15T22:23:21.000Z (about 8 years ago)
- Last Synced: 2024-10-15T02:06:56.052Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 61.5 KB
- Stars: 47
- Watchers: 7
- Forks: 33
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## About
[PassportJS](http://passportjs.org) auth library integrated into CompoundJS. This package allows authentication without any extra coding - just configure and use.
## Setup
**Step 1:** Install dependenciesAdd `compound-passport`, `passport`, and any providers used to your `package.json` and run `npm install`. Remember to add the used Passport Strategies to your `package.json`, e.g. `passport-facebook`, `passport-github`, etc. -- see [PassportJS providers](http://passportjs.org/guide/providers/).
**Step 2:** Configure
Put the following configuration in ```config/passport.yml```.
```yaml
development:
baseURL: 'http://localhost:3000/'
logoutURL: 'http://localhost:3000/auth/'
local: true
google: true
github:
clientID: "a8578b8dc47834908338"
secret: "d8107d7cd75fc8ee1f12cf1f38b3aa065c3ec2ac"
linkedin:
apiKey: "3s708f1uys4x"
secret: "p3iBqlybJ5WNTINv"
production:
baseURL: 'http://node-js.ru/'
logoutURL: 'http://node-js.ru/admin/'
github:
clientID: "...."
secret: "...."
```To separate configuration from code simply use "process.env" directly in the configuration file:
```yaml
development:
baseURL: 'http://localhost:3000/'
logoutURL: 'http://localhost:3000/auth/'
local: true
google: true
github:
clientId: "process.env.GITHUB_API_KEY"
secret: "process.env.GITHUB_API_SECRET"
linkedin:
apiKey: "process.env.LINKEDIN_API_KEY"
secret: "process.env.LINKEDIN_API_SECRET"
production:
baseURL: 'http://node-js.ru/'
logoutURL: 'http://node-js.ru/admin/'
github:
clientID: "...."
secret: "...."
```The module will then automatically read environment variables and use those.
**Step 3:** Add module
Add module to ```config/autoload.js```:
```javascript
module.exports = function() {
return [require('compound-passport')];
};
```## Use
All authentication routes starts with `/auth/PROVIDERNAME`
Just visit `/auth/google` to sign in with google:<% link_to('Sign in with google', '/auth/google') %>
<% link_to('Sign in with linkedin', '/auth/linkedin') %>
<% link_to('Sign in with github', '/auth/github') %>Callback urls:
- GitHub: `/auth/github/callback`
- LinkedIn: `/auth/linkedin/callback`Logout:
Provide by `logout()` function from `passportjs`, see [passportjs#logout](http://passportjs.org/guide/logout/).
Easily configurable in config.yml file, just add logout redirection url (default is '/'):
```yaml
logoutURL: '/auth/'
```Example before filter (describe in your application controller):
```javascript
before(function requireManager() {
if (!session.passport.user) {
req.session.redirect = req.path;
redirect('/auth/linkedin');
} else {
User.find(session.passport.user, function (err, user) {
if (user && user.email === '[email protected]') {
req.user = user;
next();
} else {
flash('error', 'You have no permission to access this area');
redirect('/');
}
});
}
});
```## MIT License
```text
Copyright (C) 2012 by Anatoliy ChakkaevPermission 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.```text
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.
```