Skip to content

Further tuning of generateAuthorizationUri #306

@geiseri

Description

@geiseri

Prerequisites

  • I have written a descriptive issue title
  • 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 provider. I get tripped there because I am using discovery and you cannot set that symbol in there.

Motivation

No response

Example

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<string> {
    const decoded = instance.jwt.verify(request.query?.state);
    ...
  },
  checkStateFunction: async function (request): Promise<boolean> {
    const decodedState = instance.jwt.verify(request?.query?.state);
    ...
  }
}); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions