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

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

Closed
Santhosh136 opened this issue Aug 14, 2023 · 1 comment
Closed

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

Santhosh136 opened this issue Aug 14, 2023 · 1 comment

Comments

@Santhosh136
Copy link

Santhosh136 commented Aug 14, 2023

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',
  };
};
@Santhosh136 Santhosh136 changed the title How to use dynamics params in custom_params of grant auth package? How to use dynamic params in custom_params of grant auth package? Aug 14, 2023
@Santhosh136 Santhosh136 changed the title How to use dynamic params in custom_params of grant auth package? How to use dynamic params in custom_params of grant? Aug 14, 2023
@simov
Copy link
Owner

simov commented Aug 14, 2023

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.

@simov simov closed this as completed Oct 10, 2023
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

2 participants