fastify / fastify/fastify-oauth2
Further tuning of generateAuthorizationUri
- Dominant language
- JavaScript
- Stars
- 319
- Forks
- 74
- Avg merge
- 7h 16m
- Merged PRs (30d)
- 1
Description
### Prerequisites
- [x] I have written a descriptive issue title
- [x] I have searched existing issues to ensure the feature has not already been requested
### 🚀 Feature Proposal
This is a bit more of an extension of #179 and #254. In my situation I would like to set the `login_hint` on the authorization endpoint call. My issue is that `callbackUriParams` is populated at registration time, and I won't know the `login_hint` until the user calls the start redirect path and there is a cookie with their username set. I tried to go the approach of using `generateAuthorizationUri` as in the example. But I had to jump through a few hoops just to get this set. There is a hack that does something almost exactly what I wish to do in the [Apple](https://github.com/fastify/fastify-oauth2/blob/main/index.js#L599) provider. I get tripped there because I am using discovery and you cannot set that symbol in there.
### Motivation
_No response_
### Example
```ts
await instance.register(oauthPlugin, {
name: "_brokerOAuth2",
scope: ["openid", "profile", "email"],
credentials: {
client: {
id: ssoProvider.clientId,
secret: ssoProvider.clientSecret
}
},
callbackUriParams: { prompt: "login" },
startRedirectPath: "/api/auth/brokerOpenid",
discovery: { issuer: ssoProvider.discoveryUrl },
callbackUri: (req) => `https://${req.hostname}${brokerCallbackRedirectPath}`,
cookie: {
secure: true,
sameSite: "none"
},
generateCallbackUriParams: function (callbackUriParams, request, scope, _state) {
try {
const upn = request.cookies["upn"];
if (!isNullish(upn)) { callbackUriParams.login_hint = upn; }
return callbackUriParams;
} catch (err) {
return callbackUriParams;
}
},
generateStateFunction: async function (request): Promise {
const decoded = instance.jwt.verify(request.query?.state);
...
},
checkStateFunction: async function (request): Promise {
const decodedState = instance.jwt.verify(request?.query?.state);
...
}
});
```
Contributor guide
Assessment
This issue has not been assessed yet.