With generating client_secret for an Oauth2 API

Asked

Viewed 55 times

2

I’m using Nodejs, but I believe the question may be useful in other languages as well. The oAuth 2 specification does not determine the size of the string that should be generated, it only informs this

VSCHAR     = %x20-7E

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

1 answer

0


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

'use strict';

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

     return { secret: value.toString(36) }
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.