oauth-example
oauth-example copied to clipboard
Fix generateAuthorizationCode without editing library
Just open model.js on line 111 change function to:
` generateAuthorizationCode: (client, user, scope,cb) => {
log({
title: 'Generate Authorization Code',
parameters: [
{ name: 'client', value: client },
{ name: 'user', value: user },
],
})
const seed = crypto.randomBytes(256)
const code = crypto
.createHash('sha1')
.update(seed)
.digest('hex')
cb(null,code)
},`
Another fix to be compatible with both callback-style and promise-style invocations :
generateAuthorizationCode: function (client, user, scope, callback) {
const generateCode = () => {
log({
title: 'Generate Authorization Code',
parameters: [
{ name: 'client', value: client },
{ name: 'user', value: user },
],
});
const seed = crypto.randomBytes(256);
const code = crypto
.createHash('sha1')
.update(seed)
.digest('hex');
return code;
};
if (callback && typeof callback === 'function') {
try {
const code = generateCode();
callback(null, code);
} catch (error) {
callback(error);
}
} else {
return new Promise((resolve, reject) => {
try {
const code = generateCode();
resolve(code);
} catch (error) {
reject(error);
}
});
}
},