Skip to content

Commit d28280f

Browse files
committed
refactor(*): linter assisted cleanup
1 parent 3da271d commit d28280f

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

index.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ function parse_authorization(authorization) {
2020

2121
var parts = authorization.split(' ');
2222

23-
if (parts.length != 2 || parts[0] != 'Basic') {
23+
if (parts.length !== 2 || parts[0] !== 'Basic') {
2424
return null;
2525
}
2626

2727
var creds = new Buffer(parts[1], 'base64').toString(),
2828
i = creds.indexOf(':');
2929

30-
if (i == -1) {
30+
if (i === -1) {
3131
return null;
3232
}
3333

@@ -38,12 +38,12 @@ function parse_authorization(authorization) {
3838
}
3939

4040
function OAuth2Provider(options) {
41-
if (arguments.length != 1) {
41+
if (arguments.length !== 1) {
4242
console.warn('OAuth2Provider(crypt_key, sign_key) constructor has been deprecated, yo.');
4343

4444
options = {
4545
crypt_key: arguments[0],
46-
sign_key: arguments[1],
46+
sign_key: arguments[1]
4747
};
4848
}
4949

@@ -68,11 +68,11 @@ OAuth2Provider.prototype.generateAccessToken = function(user_id, client_id, extr
6868

6969
// JWT access_token
7070
access_token = jwt.encode(_.extend(extra_data, token_options), client_secret);
71-
refresh_token = this.serializer.stringify([user_id, client_id, parseInt(moment().unix())]);
71+
refresh_token = this.serializer.stringify([user_id, client_id, parseInt(moment().unix(), 10)]);
7272

7373
var out = _.extend(token_options, {
7474
access_token: access_token,
75-
refresh_token: refresh_token,
75+
refresh_token: refresh_token
7676
});
7777
return out;
7878
};
@@ -105,8 +105,8 @@ OAuth2Provider.prototype.oauth = function() {
105105
return function(req, res, next) {
106106
var uri = ~req.url.indexOf('?') ? req.url.substr(0, req.url.indexOf('?')) : req.url;
107107

108-
if (req.method == 'GET' && self.options.authorize_uri == uri) {
109-
var client_id = req.query.client_id,
108+
if (req.method === 'GET' && self.options.authorize_uri === uri) {
109+
var client_id = req.query.client_id,
110110
redirect_uri = req.query.redirect_uri;
111111

112112
if (!client_id || !redirect_uri) {
@@ -125,12 +125,13 @@ OAuth2Provider.prototype.oauth = function() {
125125
self.emit('authorize_form', req, res, client_id, authorize_url);
126126
});
127127

128-
} else if (req.method == 'POST' && self.options.authorize_uri == uri) {
129-
var client_id = (req.query.client_id || req.body.client_id),
130-
redirect_uri = (req.query.redirect_uri || req.body.redirect_uri),
131-
response_type = (req.query.response_type || req.body.response_type) || 'code',
132-
state = (req.query.state || req.body.state),
133-
x_user_id = (req.query.x_user_id || req.body.x_user_id);
128+
} else if (req.method === 'POST' && self.options.authorize_uri === uri) {
129+
var response_type = (req.query.response_type || req.body.response_type) || 'code',
130+
state = (req.query.state || req.body.state),
131+
x_user_id = (req.query.x_user_id || req.body.x_user_id);
132+
133+
redirect_uri = (req.query.redirect_uri || req.body.redirect_uri);
134+
client_id = (req.query.client_id || req.body.client_id);
134135

135136
var url = redirect_uri;
136137

@@ -143,7 +144,7 @@ OAuth2Provider.prototype.oauth = function() {
143144
}
144145

145146
if ('allow' in req.body) {
146-
if ('token' == response_type) {
147+
if ('token' === response_type) {
147148
var user_id;
148149

149150
try {
@@ -171,7 +172,7 @@ OAuth2Provider.prototype.oauth = function() {
171172

172173
self.emit('save_grant', req, client_id, code, function() {
173174
var extras = {
174-
code: code,
175+
code: code
175176
};
176177

177178
// pass back anti-CSRF opaque value
@@ -191,12 +192,12 @@ OAuth2Provider.prototype.oauth = function() {
191192
res.writeHead(303, {Location: url});
192193
res.end();
193194
}
195+
} else if (req.method === 'POST' && self.options.access_token_uri === uri) {
196+
var client_secret = req.body.client_secret,
197+
code = req.body.code;
194198

195-
} else if (req.method == 'POST' && self.options.access_token_uri == uri) {
196-
var client_id = req.body.client_id,
197-
client_secret = req.body.client_secret,
198-
redirect_uri = req.body.redirect_uri,
199-
code = req.body.code;
199+
redirect_uri = req.body.redirect_uri;
200+
client_id = req.body.client_id;
200201

201202
if (!client_id || !client_secret) {
202203
var authorization = parse_authorization(req.headers.authorization);
@@ -210,8 +211,8 @@ OAuth2Provider.prototype.oauth = function() {
210211
client_secret = authorization[1];
211212
}
212213

213-
if ('password' == req.body.grant_type) {
214-
if (self.listeners('client_auth').length == 0) {
214+
if ('password' === req.body.grant_type) {
215+
if (self.listeners('client_auth').length === 0) {
215216
res.writeHead(401);
216217
return res.end('client authentication not supported');
217218
}

0 commit comments

Comments
 (0)