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

[Question/Feature Request] Allow to pass additional custom function for parsing UserInfo #93

Open
bkupidura opened this issue Feb 23, 2022 · 1 comment

Comments

@bkupidura
Copy link

bkupidura commented Feb 23, 2022

Im using passport-openidconnect with Authelia.
With current implementation, only well defined list of UserInfo data (https://github.com/jaredhanson/passport-openidconnect/blob/master/lib/profile.js) can be passed to verify function.

It would be nice to be able pass additional parsing function from Strategy options.

It can work like this:

new OpenIDConnectStrategy({
  ...,
  customParse: function(profile, json){
    if (json.groups) { profile.groups = json.groups; }
  }
})
            var profile = Profile.parse(json);
            if (typeof options.customParse === 'function') {
                options.customParse(profile, json)
            }
            loaded(profile, json, body);

This way passport-openidconnect will allow users to parse any UserInfo. If this can be already achieved somehow, can you please clarify how?

(Sorry for my pure JS code example ;))

@regnete
Copy link

regnete commented Mar 4, 2022

In an earlier version of this startegy, the verify callback had access to the claims. So we were able to acces some custom properties in the claim and apply them to the profile.
In the current version, claims is not passed in anymore.
A custom parse function seems to be the most elegnat solution for this requirement.
Please think about adding a custom parse function for the context too.

We are currently working arround this issue with a very uggly hack/workarround.

Overwrite the strategies private _shouldLoadUserProfile method, as it has access to claims.
Then remember claims as a property of request.

// HACK: sadly the basic impl doesn't pass the claims to openIDVerifyCallback anymore
this._shouldLoadUserProfile = (req, claims, done) => {
     req['passport_' + this.name + "_claims"] = claims;
     done(null, false);
}

In your verify callback, get the claims from the request. Must set passReqToCallback=true in the strategy options!

const claims = req['passport_' + this.name + "_claims"];
delete req['passport_' + this.name + "_claims"];

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