Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generateAuthorizationCode without editing library #29

Open
farazfaraji opened this issue Jul 6, 2022 · 1 comment
Open

Fix generateAuthorizationCode without editing library #29

farazfaraji opened this issue Jul 6, 2022 · 1 comment

Comments

@farazfaraji
Copy link

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)

},`

@Dawebxx
Copy link

Dawebxx commented Oct 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants