function OAuth2Server(config) { if (!(this instanceof OAuth2Server)) return new OAuth2Server(config); config = config || {}; if (!config.model) throw new Error('No model supplied to OAuth2Server'); this.model = config.model; this.grants = config.grants || []; this.debug = config.debug || function () {}; if (typeof this.debug !== 'function') { this.debug = console.log; } this.passthroughErrors = config.passthroughErrors; this.continueAfterResponse = config.continueAfterResponse; this.accessTokenLifetime = config.accessTokenLifetime !== undefined ? config.accessTokenLifetime : 3600; this.refreshTokenLifetime = config.refreshTokenLifetime !== undefined ? config.refreshTokenLifetime : 1209600; this.authCodeLifetime = config.authCodeLifetime || 30; this.regex = { clientId: config.clientIdRegex || /^[a-z0-9-_]{3,40}$/i, grantType: new RegExp('^(' + this.grants.join('|') + ')$', 'i') }; }
n/a
function OAuth2Error(error, description, err) {
if (!(this instanceof OAuth2Error))
return new OAuth2Error(error, description, err);
Error.call(this);
this.name = this.constructor.name;
if (err instanceof Error) {
this.message = err.message;
this.stack = err.stack;
} else {
this.message = description;
Error.captureStackTrace(this, this.constructor);
}
this.headers = {
'Cache-Control': 'no-store',
'Pragma': 'no-cache'
};
switch (error) {
case 'invalid_client':
this.headers['WWW-Authenticate'] = 'Basic realm="Service"';
/* falls through */
case 'invalid_grant':
case 'invalid_request':
this.code = 400;
break;
case 'invalid_token':
this.code = 401;
break;
case 'server_error':
this.code = 503;
break;
default:
this.code = 500;
}
this.error = error;
this.error_description = description || error;
}
n/a
function OAuth2Error(error, description, err) {
if (!(this instanceof OAuth2Error))
return new OAuth2Error(error, description, err);
Error.call(this);
this.name = this.constructor.name;
if (err instanceof Error) {
this.message = err.message;
this.stack = err.stack;
} else {
this.message = description;
Error.captureStackTrace(this, this.constructor);
}
this.headers = {
'Cache-Control': 'no-store',
'Pragma': 'no-cache'
};
switch (error) {
case 'invalid_client':
this.headers['WWW-Authenticate'] = 'Basic realm="Service"';
/* falls through */
case 'invalid_grant':
case 'invalid_request':
this.code = 400;
break;
case 'invalid_token':
this.code = 401;
break;
case 'server_error':
this.code = 503;
break;
default:
this.code = 500;
}
this.error = error;
this.error_description = description || error;
}
n/a
function Error() { [native code] }
n/a