Skip to content

Commit dc22e5d

Browse files
committed
Standardize the error message returned when there is a missing client_id or secret
1 parent fc3035a commit dc22e5d

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/error_credentials.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// error_credentials
2+
3+
module.exports = function(p) {
4+
return {
5+
error : ((p.client_id || p.id) ? "invalid" : "required") + "_credentials",
6+
error_message : "Could not find the credentials that match the provided client_id '"+(p.client_id || p.id)+"'",
7+
state : p.state || ''
8+
};
9+
};

src/oauth1.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var param = require('./utils/param');
77
var sign = require('./sign');
88
var url = require('url');
99
var request = require('./utils/request');
10+
var error_credentials = require('./error_credentials');
1011

1112
// token=>secret lookup
1213
var _token_secrets = {};
@@ -15,6 +16,12 @@ var _token_secrets = {};
1516
module.exports = function(p, callback){
1617

1718

19+
// Missing Credentials
20+
if (!p.client_secret) {
21+
callback(p.redirect_uri, error_credentials(p));
22+
return;
23+
}
24+
1825

1926
//
2027
// Get the Authorization path
@@ -138,21 +145,6 @@ module.exports = function(p, callback){
138145
}
139146

140147

141-
//
142-
// Find the client secret
143-
// Get the client secret
144-
//
145-
146-
147-
if(!client_secret){
148-
callback( p.redirect_uri, {
149-
error : ( p.client_id ? "invalid" : "required" ) + "_credentials",
150-
error_message : "Credentials were not recognised",
151-
state : p.state || ''
152-
});
153-
return;
154-
}
155-
156148
// Sign the request using the application credentials
157149
var signed_url = sign( path, opts, client_secret, token_secret || null);
158150

src/oauth2.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
var request = require('./utils/request');
77
var param = require('./utils/param');
88
var url = require('url');
9+
var error_credentials = require('./error_credentials');
910

1011
module.exports = function(p, callback){
1112

12-
if(!p.client_secret){
13-
return callback({
14-
error : ( (p.client_id || p.id) ? "invalid" : "required" ) + "_credentials",
15-
error_message : "Could not find the credentials for signing this request, ensure that the correct client_id is passed",
16-
state : p.state || ''
17-
});
13+
// Missing Credentials
14+
if (!p.client_secret) {
15+
callback(error_credentials(p));
16+
return;
1817
}
1918

2019
// Make the OAuth2 request

0 commit comments

Comments
 (0)