oauth-example icon indicating copy to clipboard operation
oauth-example copied to clipboard

Fix generateAuthorizationCode without editing library

Open farazfaraji opened this issue 3 years ago • 1 comments

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)

},`

farazfaraji avatar Jul 06 '22 11:07 farazfaraji

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);
       }
     });
   }
 },

Dawebxx avatar Oct 23 '24 22:10 Dawebxx