Install Oauth 2.0 Mock Server

This should help testing Oauth 2.0 implementation.

Step-by-step guide

  1. Install Node.js (https://nodejs.org/en/).
  2. Run CMD as Administrator.
  3. Go to Node.js installation folder (usually "Program Files\nodejs").
  4. Install NPM using the command "npm i mock-oauth-2-server" (if you are behind a proxy then follow this instruction first https://forum.freecodecamp.org/t/npm-behind-a-proxy-server/19386).
  5. Create a server.js as follows:

    const oauth2 = require('mock-oauth-2-server');
    
    const mockData = {
      client: {
        id : 'oauth2_application_client_id',
        secret : 'oauth2_application_secret',
        redirectUris : ['http://localhost:5000/oauth2/redirect/callback'],
        grants: ['authorization_code']
      },
      user: {
        id : '123',
        uuid : 'dkalfyeoiqajaof',
        email: 'brad@email.com'
      },
      jwtSecret: 'jwt_secret_key'
    };
    
    let mock = new oauth2(mockData);
    
    mock.start();
  6. Start using command "node server".

 

Note: to generate access token, use:

 const defaultGenerateAccessToken(client, user, scope) {
  return jwt.sign(user, 'im_a_secret', { algorithm: 'HS512', jwtid: uuid() });
}

 

 

Filter by label

There are no items with the selected labels at this time.