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

Customization hooks are not working #274

Closed
olegsmetanin opened this issue Oct 6, 2023 · 2 comments
Closed

Customization hooks are not working #274

olegsmetanin opened this issue Oct 6, 2023 · 2 comments

Comments

@olegsmetanin
Copy link

Summary

beforeTokenSigning hook does not allow state to be changed.

Steps to Reproduce

  1. run
const { OAuth2Server } = require('oauth2-mock-server');

(async () => {
    let server = new OAuth2Server();
    // Generate a new RSA key and add it to the keystore
    await server.issuer.keys.generate('RS256');
    server.service.once('beforeTokenSigning', (token, req) => {
      token.payload.exp = token.payload.iat + 400;
    });

    // Start the server
    await server.start(8080);

    console.log(`OAuth 2 issuer is ${server.issuer.url}`);

})();
  1. run
curl 'http://localhost:8080/authorize?response_type=code&redirect_uri=http://localhost:8081/callback&scope=dummy_scope&state=state123&client_id=abcecedf&nonce=21ba8e4a-26af-4538-b98a-bccf031f6754' \
  -H 'Accept: text/html,application/xhtml+xml'

Found. Redirecting to http://localhost:8081/callback?code=8fcbdb52-f2ad-4f43-aaf3-501d45cc7723&state=state123

  1. get token by code
curl -X POST http://localhost:8080/token \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "grant_type=authorization_code&client_id=abcecedf&code=8fcbdb52-f2ad-4f43-aaf3-501d45cc7723"
  1. decode id_token
npx jwt-cli --output=json eyJraWQiOiIxNDljYjRiZmJmZDQxZGM2ZGEwMzcxZTFjZjdmODU0Y2UxNDZkMTZkOGRkNjRhMTAwODYwMjE4YjE3NDdkZGFjZmNiYjg3MDBlMjY5MmUwMCIsInR5cCI6IkpXVCIsImFsZyI6IlJTMjU2In0.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE2OTY1NDUwNjcsImV4cCI6MTY5NjU0ODY2NywibmJmIjoxNjk2NTQ1MDU3LCJzdWIiOiJqb2huZG9lIiwiYXVkIjoiYWJjZWNlZGYifQ.pSxO_m8BCuM5lMWgHV9Vs9omKahTylitPA8nEn_VOjeyBdqZGV2C0EI_x2qCjCkMqS4Dc9fyP25BHinAUJ9X613Tw1t4_wzaYQVdLIKZxBBYAVOzvOOiosY6jYLDtz6jKFd6kecjR57u8WurxnP-msQK4D5_tYhrLhH9xBAcjcXMIIgjX4SN9etaiksaHwkucpSDqxTWs9aNJfb67k0sWOL5lwGuFKIgLKgcFiBwwaPyTk5h4LCmOY-dobWBFDXTSUFcOqZjmMWIbSLaFuWvEmaLHJyucLKc9IIQW-wbwGgTSsccTaQXINdKbinhy1WxB2T0Bazh2ANQsh7Sl6v26g
  1. check that payload.exp is not changed

Expected Behavior

payload.exp is changed

Screenshots

Environment

  • oauth2-mock-server version: (7.0.0)
  • Noje.JS version: (v19.8.1)
  • NPM version: (9.5.1)
  • Operating System: (Windows 11)

Additional Context

@poveden
Copy link
Contributor

poveden commented Oct 27, 2023

Hi @olegsmetanin! I'm able to reproduce your issue... but with a caveat.

When I run your test code for the first time, I get what you expect to happen (i.e. exp = iat + 400), but if I run it a second time, I get the default (exp = iat + 3600).

This should be expected, as your test code hooks on beforeTokenSigning once.

Perhaps you meant to use server.service.on(...) instead of server.service.once(...)?

@nulltoken
Copy link
Contributor

@olegsmetanin Closing due to inactivity. Feel free to message back would you want to discuss this further.

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

3 participants