Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ npm-debug.log

# Mac OS X
.DS_Store

!intl/
intl/*
!intl/en/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be ordered like this: (Thats my two cents)

build/
reports/
!intl/
intl/*
!intl/en/

# Node.js
node_modules/
npm-debug.log

# Mac OS X
.DS_Store

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not bikeshed here. It's going to work wherever you add it (and there is no convention for .gitignores across all LoopBack projects yet -- maybe we should come up with one and then fix them all at that time).

build/
reports/
!intl/
intl/*
!intl/en/

This part isn't alphabetized correctly in your example anyways.

Copy link
Copy Markdown
Member

@Amir-61 Amir-61 Jul 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not bikeshed here.

Sure!

But basically I did not mean alphabetical order; I mean order based on the categories

...
# Node.js
...
# Mac OS X
...

Copy link
Copy Markdown
Contributor

@superkhau superkhau Jul 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, if we actually went with it, it should be a combination of both. Categories and alphabetically inside each category. Anyways, enough 🚲 🏠 ;)

67 changes: 67 additions & 0 deletions intl/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"102a3213ff01fc1b03faa5cbe720e6c0": "Invalid authorization code",
"12df3715215d39fdb1c5c19775091f31": "{{OAuth2orize}} requires body parsing. Did you forget {{app.use(express.bodyParser())}}?",
"37086a106da98d5322d134d7905d1817": "Missing required parameter: {{code}}",
"cdee717bf439af4c84eabb54b82c13af": "{{oauth2orize.authorizationCode}} exchange requires an issue callback",
"aaee2c79ab90ccc63b9d46795e19620a": "{{oauth2orize.clientCredentials}} exchange requires an issue callback",
"ae02475e560f64afdcf6d02bc80dcb0e": "Invalid client credentials",
"06f6133efc10bf1f9a2c6b5161c66fba": "Request body not parsed. Use {{bodyParser}} middleware.",
"76d075ea0325d32667fad67c446e469b": "invalid {{JWT}}",
"a198c4335c42739230d7d8afacdc109d": "{{OAuth 2.0 jwtBearer}} exchange middleware requires an {{issue}} function.",
"fcdd5cf7956698312e899ddb708abbaf": "missing assertion parameter",
"47db77dd8ab3aa3c3ec1e6c955c0cc01": "Missing required parameter: {{username}}",
"cbd12265f4ab78b30a0977e37aefcf37": "Missing required parameter: {{password}}",
"d837f7c0309bf4816cbbb22b57473733": "{{oauth2orize.password}} exchange requires an {{issue}} callback",
"ff7883d90a5fe850e026885759165406": "Invalid resource owner credentials",
"6d3b5c2b2c7c20cd8907a0b090f0e89c": "Invalid refresh token",
"740f3fb2bd1358d65943e735224d23e5": "Missing required parameter: {{refresh_token}}",
"ec9ddf242c3da3b5cf44def6398706ec": "{{oauth2orize.refreshToken}} exchange requires an {{issue}} callback",
"3bffb3bbef4312d6bcbabd3240e79ef2": "{{oauth2orize.code}} grant requires an {{issue}} callback",
"6e0122e493bd949f408c1421fc757b95": "Unable to issue redirect for {{OAuth 2.0}} transaction",
"d36b1a9f8719a56a091ed6c89d3cd1fa": "Request denied by authorization server",
"f50708df489d7811db692c0b601483f8": "Missing required parameter: {{client_id}}",
"bcb1c003530e6fb715ad605ea7fe83d9": "{{oauth2orize.token}} grant requires an {{issue}} callback",
"83459aaa8e2d81c7fad2b899ad0cbf57": "The {{OAuth2}} component was not configured for this application.",
"083123c0a745a514ce06fa527c151a46": "{{oauth2orize.authorization}} middleware requires a {{server}} argument",
"092f3dd9c9bde61eed97f67459b46a7e": "Unsupported response type: {0}",
"24ff616d05fe6b8dca8859d9dafa729e": "Invalid client",
"2caa676b18561101c92e69d70820b1bf": "{{OAuth2orize}} requires {{session}} support. Did you forget {{app.use(express.session(...))}}?",
"43a5b5bf0c7dd0bf5fec2601fe347245": "Invalid request: {{redirect_uri}} is missing",
"8782860f8d60f2bdb6f67d623dd7e51f": "{{oauth2orize.authorization}} middleware requires a {{validate}} function",
"ec30fea412580b611d7a274ee1163e5c": "Missing required parameter: {{response_type}}",
"14b06036ad206e2b038840c24e677b4d": "{{OAuth2orize}} requires transaction support. Did you forget {{oauth2orize.transactionLoader(...)}}?",
"7175ea69be895be338ca9f9168268dab": "{{oauth2orize.decision}} middleware requires a {{server}} argument",
"a7b39a5a13fdba4772a83e07cb864156": "Unable to load {{OAuth 2.0}} transactions from session",
"54d8df1f46d3358dd33ba274a537b519": "Unsupported token type: {0}",
"a23d7ec09a60c8bbd119d8287d8b5805": "{{oauth2orize.revoke}} middleware requires a {{revokeToken}} function",
"d3dd8b2220bba70a6e7e44af24a4157c": "Missing required parameter: {{token}}",
"f06abf2e08aba65a62f4486bc2418413": "{{oauth2orize.revoke}} middleware requires a {{server}} argument",
"4428b355c8ba3e248b8fc0857e2181a0": "Unsupported grant type: {0}",
"bac74f7415259e303903cfc8a7bcc4df": "{{oauth2orize.token}} middleware requires a {{server}} argument",
"5bc4d117f87ba20efb8cdd4c988ed46d": "{{oauth2orize.transactionLoader}} middleware requires a {{server}} argument",
"8000aa2c64d9c95c406053764fc33f64": "Unauthorized client",
"b1af8f34c3d25bd59189205046665bfd": "Missing required parameter: {0}",
"f24b75ecdc45edb84b0c9fec3b6f1e5b": "Unable to load {{OAuth 2.0}} transaction: {0}",
"452b7bd4aed1b69b7c20fb701377c4eb": "Unauthorized {{redirectURI}}: {0}",
"e173a3cecca19bcbf528408adc001750": "Unauthorized response type: {0}",
"eb30f051fcf0e7338bf4d8489f583378": "Unauthorized {{scope}}: {0}",
"ed5c8e0055b1cae433e4c393ae04d555": "Invalid items: {0}",
"fef19f407c562658e0132f1625ce968b": "Unauthorized grant type: {0}",
"10b283f781f47e879e25e3b3b84f85e3": "Permission denied by {0}",
"19d7beb3c393b20162c2c43135b4f1c0": "Authorization code is expired",
"1e1b2073df0a8963670e9ed1e181dfe8": "Invalid {{JWT}}: {0}",
"3cfcae051965e0da5f704a334e1e884c": "Client id mismatches",
"839544ec984d6290cd45669efdd39699": "Redirect {{uri}} mismatches",
"fa925eb4771bd2897f14b1de78ca0ed2": "Invalid subject: {0}",
"53c21d3a92686e2956d527d097e1e1b9": "Access token has invalid {{user id}}: {0}",
"d83b55a5dfd3e16ca22699e39b072f3f": "Access token has invalid {{app id}}: {0}",
"f483b2bebd08d285c7009c6812f5ba24": "Access token is expired",
"9508d060bc6fd6e25cb4d0c00ea0480d": "Insufficient scope",
"373b2ad70311b6537ad42719088da022": "Failed to deserialize client. Register deserialization function using {{deserializeClient()}}.",
"5b853ac61fab20ec62d53e183e067ec3": "Failed to serialize client. Register serialization function using {{serializeClient()}}.",
"a2f3ad97b7b05618b6722b8f07e9f805": "{{OAuth 2.0 JWT}} bearer strategy requires a verify callback",
"a82c6b0f0db10b6e198e99068e765570": "{{OAuth 2.0 JWT}} bearer strategy requires an audience option",
"db8b02ad229f45cbb12e0d9845b09eb2": "{{OAuth 2.0 JWT}} bearer strategy requires a keying callback",
"b1eb21b6d32dde679f9b4bf0b2e0939d": "{{MACStrategy}} requires a verify callback",
"e82c91e82424949d4390135e5e8adf1c": "Invalid {{MAC}} token"
}
24 changes: 13 additions & 11 deletions lib/exchange/authorizationCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/**
* Module dependencies.
*/
var SG = require('strong-globalize');
var g = SG();
Copy link
Copy Markdown
Contributor

@superkhau superkhau Jul 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can shorten these to var g = require('strong-globalize'); See https://github.com/strongloop-internal/loopback-knowledge-base/pull/51/files

I'll leave it up to you for whether you want to address it though since these are nitpicks anyways.

var utils = require('../utils')
, TokenError = require('../errors/tokenerror');

Expand Down Expand Up @@ -66,37 +68,37 @@ module.exports = function(options, issue) {
options = undefined;
}
options = options || {};
if (!issue) { throw new TypeError('oauth2orize.authorizationCode exchange requires an issue callback'); }

if (!issue) { throw new TypeError(g.f('{{oauth2orize.authorizationCode}} exchange requires an issue callback')); }

var userProperty = options.userProperty || 'user';

return function authorization_code(req, res, next) {
if (!req.body) { return next(new Error('OAuth2orize requires body parsing. Did you forget app.use(express.bodyParser())?')); }
if (!req.body) { return next(new Error(g.f('{{OAuth2orize}} requires body parsing. Did you forget {{app.use(express.bodyParser())}}?'))); }

// The 'user' property of `req` holds the authenticated user. In the case
// of the token endpoint, the property will contain the OAuth 2.0 client.
var client = req[userProperty]
, code = req.body.code
, redirectURI = req.body.redirect_uri;
if (!code) { return next(new TokenError('Missing required parameter: code', 'invalid_request')); }

if (!code) { return next(new TokenError(g.f('Missing required parameter: {{code}}'), 'invalid_request')); }

try {
issue(client, code, redirectURI, function(err, accessToken, refreshToken, params) {
if (err) { return next(err); }
if (!accessToken) { return next(new TokenError('Invalid authorization code', 'invalid_grant')); }
if (!accessToken) { return next(new TokenError(g.f('Invalid authorization code'), 'invalid_grant')); }
if (refreshToken && typeof refreshToken == 'object') {
params = refreshToken;
refreshToken = null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated changes

var tok = {};
tok.access_token = accessToken;
if (refreshToken) { tok.refresh_token = refreshToken; }
if (params) { utils.merge(tok, params); }
tok.token_type = tok.token_type || 'Bearer';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

var json = JSON.stringify(tok);
res.setHeader('Content-Type', 'application/json');
res.setHeader('Cache-Control', 'no-store');
Expand Down
22 changes: 12 additions & 10 deletions lib/exchange/clientCredentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
/**
* Module dependencies.
*/
var SG = require('strong-globalize');
var g = SG();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorten to single line

var utils = require('../utils')
, TokenError = require('../errors/tokenerror');


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

/**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines have to be first in the file.

* Exchanges client credentials for access tokens.
*
Expand Down Expand Up @@ -65,8 +67,8 @@ module.exports = function(options, issue) {
options = undefined;
}
options = options || {};
if (!issue) { throw new TypeError('oauth2orize.clientCredentials exchange requires an issue callback'); }

if (!issue) { throw new TypeError(g.f('{{oauth2orize.clientCredentials}} exchange requires an issue callback')); }

var userProperty = options.userProperty || 'user';

Expand All @@ -81,13 +83,13 @@ module.exports = function(options, issue) {
}

return function client_credentials(req, res, next) {
if (!req.body) { return next(new Error('OAuth2orize requires body parsing. Did you forget app.use(express.bodyParser())?')); }
if (!req.body) { return next(new Error(g.f('{{OAuth2orize}} requires body parsing. Did you forget {{app.use(express.bodyParser())}}?'))); }

// The 'user' property of `req` holds the authenticated user. In the case
// of the token endpoint, the property will contain the OAuth 2.0 client.
var client = req[userProperty]
, scope = req.body.scope;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

if (scope) {
for (var i = 0, len = separators.length; i < len; i++) {
var separated = scope.split(separators[i]);
Expand All @@ -100,11 +102,11 @@ module.exports = function(options, issue) {
}
if (!Array.isArray(scope)) { scope = [ scope ]; }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

function issued(err, accessToken, refreshToken, params) {
if (err) { return next(err); }
if (!accessToken) {
return next(new TokenError('Invalid client credentials', 'invalid_grant'));
return next(new TokenError(g.f('Invalid client credentials'), 'invalid_grant'));
}
if (refreshToken && typeof refreshToken === 'object') {
params = refreshToken;
Expand All @@ -116,14 +118,14 @@ module.exports = function(options, issue) {
if (refreshToken) { tok.refresh_token = refreshToken; }
if (params) { utils.merge(tok, params); }
tok.token_type = tok.token_type || 'Bearer';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

var json = JSON.stringify(tok);
res.setHeader('Content-Type', 'application/json');
res.setHeader('Cache-Control', 'no-store');
res.setHeader('Pragma', 'no-cache');
res.end(json);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

try {
var arity = issue.length;
if (arity === 4) {
Expand Down
10 changes: 6 additions & 4 deletions lib/exchange/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/**
* Module dependencies.
*/
var SG = require('strong-globalize');
var g = SG();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single line

var AuthorizationError = require('../errors/authorizationerror');

/**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to 1st line

Expand Down Expand Up @@ -97,14 +99,14 @@ module.exports = function jwtBearer(options, issue) {
options = options || {};

if (!issue) {
throw new Error('OAuth 2.0 jwtBearer exchange middleware requires an issue function.');
throw new Error(g.f('{{OAuth 2.0 jwtBearer}} exchange middleware requires an {{issue}} function.'));
}

var userProperty = options.userProperty || 'user';

return function jwt_bearer(req, res, next) {
if (!req.body) {
return next(new Error('Request body not parsed. Use bodyParser middleware.'));
return next(new Error(g.f('Request body not parsed. Use {{bodyParser}} middleware.')));
}

// The 'user' property of `req` holds the authenticated user. In the case
Expand All @@ -115,7 +117,7 @@ module.exports = function jwtBearer(options, issue) {
, separator = '.';

if (!jwtBearer) {
return next(new AuthorizationError('missing assertion parameter', 'invalid_request'));
return next(new AuthorizationError(g.f('missing assertion parameter'), 'invalid_request'));
}

contents = jwtBearer.split(separator);
Expand All @@ -129,7 +131,7 @@ module.exports = function jwtBearer(options, issue) {
return next(err);
}
if (!accessToken) {
return next(new AuthorizationError('invalid JWT', 'invalid_grant'));
return next(new AuthorizationError(g.f('invalid {{JWT}}'), 'invalid_grant'));
}

var tok = {};
Expand Down
26 changes: 14 additions & 12 deletions lib/exchange/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/**
* Module dependencies.
*/
var SG = require('strong-globalize');
var g = SG();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single line

var utils = require('../utils')
, TokenError = require('../errors/tokenerror');

Expand Down Expand Up @@ -67,7 +69,7 @@ module.exports = function(options, issue) {
}
options = options || {};

if (!issue) { throw new TypeError('oauth2orize.password exchange requires an issue callback'); }
if (!issue) { throw new TypeError(g.f('{{oauth2orize.password}} exchange requires an {{issue}} callback')); }

var userProperty = options.userProperty || 'user';

Expand All @@ -82,18 +84,18 @@ module.exports = function(options, issue) {
}

return function password(req, res, next) {
if (!req.body) { return next(new Error('OAuth2orize requires body parsing. Did you forget app.use(express.bodyParser())?')); }
if (!req.body) { return next(new Error(g.f('{{OAuth2orize}} requires body parsing. Did you forget {{app.use(express.bodyParser())}}?'))); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{{app.use(express.bodyParser())}}

// The 'user' property of `req` holds the authenticated user. In the case
// of the token endpoint, the property will contain the OAuth 2.0 client.
var client = req[userProperty]
, username = req.body.username
, passwd = req.body.password
, scope = req.body.scope;
if (!username) { return next(new TokenError('Missing required parameter: username', 'invalid_request')); }
if (!passwd) { return next(new TokenError('Missing required parameter: password', 'invalid_request')); }

if (!username) { return next(new TokenError(g.f('Missing required parameter: {{username}}'), 'invalid_request')); }
if (!passwd) { return next(new TokenError(g.f('Missing required parameter: {{password}}'), 'invalid_request')); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For both these lines, end bracket in the wrong place, should be in the first arg.

if (scope) {
for (var i = 0, len = separators.length; i < len; i++) {
var separated = scope.split(separators[i]);
Expand All @@ -106,28 +108,28 @@ module.exports = function(options, issue) {
}
if (!Array.isArray(scope)) { scope = [ scope ]; }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

function issued(err, accessToken, refreshToken, params) {
if (err) { return next(err); }
if (!accessToken) { return next(new TokenError('Invalid resource owner credentials', 'invalid_grant')); }
if (!accessToken) { return next(new TokenError(g.f('Invalid resource owner credentials'), 'invalid_grant')); }
if (refreshToken && typeof refreshToken == 'object') {
params = refreshToken;
refreshToken = null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

var tok = {};
tok.access_token = accessToken;
if (refreshToken) { tok.refresh_token = refreshToken; }
if (params) { utils.merge(tok, params); }
tok.token_type = tok.token_type || 'Bearer';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

var json = JSON.stringify(tok);
res.setHeader('Content-Type', 'application/json');
res.setHeader('Cache-Control', 'no-store');
res.setHeader('Pragma', 'no-cache');
res.end(json);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

try {
var arity = issue.length;
if (arity === 5) {
Expand Down
Loading