Contains method to authenticate and authorize
- Source:
Example
const protector = require('./lib/protector')
var treant = protector({
db: dbclient,
gClientId: '327834646153-27e424bo1lpofea0lkfs8bvrf7sv5j2e.apps.googleusercontent.com',
gClientSecret: 'y7RCBAr4AT26oACJBJUSJIxv',
gRedirectUrl: 'http://localhost:9001/v1/oauth/login',
gScopes: [
'https://www.googleapis.com/auth/plus.me',
'profile',
'email'
],
privateKeyPath: '/usr/lib/node_module/gwisp/gwisp.key',
tokenTimeout: 1800
})
Classes
Type Definitions
AuthOptions
Options to authorize
Type:
- object
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
getAcc |
boolean |
<optional> |
false | if true, retrieve account from database and assign to req.account |
group |
string |
<optional> |
null | Require account must in specify group If this field is null, no verify group of account |
msg401 |
string |
<optional> |
must login to perform this action | Message responses to endpoint if authenticate is not successful |
msg403 |
string |
<optional> |
must have correct permission to perform this action | Message responses to endpoint if authorize is not successful |
- Source:
Example
var authOptions = {
group: 'root',
msg403: 'must have root permission to perform this action'
}
TreantConfig
Configuration of trean protector
Type:
- object
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
db |
module:mongodb.MongoClient | Instance of connection to mongodb |
||
gClientId |
string | Identify of application of google |
||
gSecrectId |
string | Identify of application of google |
||
gRedirectUrl |
string | Address which call after google authenticate successfully |
||
gScopes |
Array.<string> | Define information which can retrieve from google after get access token |
||
privateKeyPath |
string | Path to PEM private file. It use to encrypt/decrypt credential as json web token. It must absolute path to ensure that path to key file is correct |
||
tokenTimeout |
number |
<optional> |
1800 | Peroid token is valid in seconds |
- Source:
Example
var config = {
db: dbclient,
gClientId: '327834646153-27e424bo1lpofea0lkfs8bvrf7sv5j2e.apps.googleusercontent.com',
gClientSecret: 'y7RCBAr4AT26oACJBJUSJIxv',
gRedirectUrl: 'http://localhost:9001/v1/oauth/login',
gScopes: [
'https://www.googleapis.com/auth/plus.me',
'profile',
'email'
],
privateKeyPath: '/usr/lib/node_module/gwisp/gwisp.key',
tokenTimeout: 1800
}