simov / grant

OAuth Proxy
MIT License
4.08k stars 257 forks source link

How to use dynamic params in custom_params of grant? #290

Closed Santhosh136 closed 11 months ago

Santhosh136 commented 1 year ago

I want to use dynamic values in custom_params option of grant config in Hapi js, can anyone help me how to achieve it? example:-

config.json

{
  "defaults": {
    "origin": "http://localhost:3000",
    "transport": "session"
  },
  "google": {
    "key": "APP_ID",
    "secret": "APP_SECRET",
    "dynamic": ["domain"],
    "custom_params": {
        "resource": `https://${domain}`
    },
    "response": ["tokens", "raw", "jwt"],
    "callback": "/hello"
  }
}

I have tried using a function to populate dynamic query params before plugin in being registered in server, but its not working

config.google.custom_params = (request) => {
  const domain = request.query.domain;
  return {
    resource: `https://${domain}`,
    response_mode: 'query',
  };
};
simov commented 1 year ago

In case you want that value set on each request, then you can use dynamic state overrides: https://github.com/simov/grant/blob/master/examples/dynamic-state/hapi.js#L9-L17

If that value is supposed to be set only once on startup, then you can update your JSON configuration before feeding it into the plugin.

Let me know if that works for you.