With generating the client_secret for an oAuth2 API

2

I'm using NodeJS, but I believe the question can be useful in other languages as well. The oAuth 2 specification does not determine the length of the string to be generated, it only informs this

VSCHAR     = %x20-7E

It is the sequence of ASCII characters. How can I generate this sequence in NodeJS?

    
asked by anonymous 29.12.2015 / 13:21

1 answer

0

The solution was to create an integer and random number and convert it to base 36. Here is an example.

'use strict';

const Client = function() {
     let value = Math.floor(Math.random() * 
          (999999999999999999999999999999999999999999999999 -     100000000000000000000000000000000000000000000000)) +
          100000000000000000000000000000000000000000000000;   

     return { secret: value.toString(36) }
};
    
31.12.2015 / 16:53