-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add user profile factory for authentication modules #3846
Comments
Hello :-) I came here from #2246 and I am a bit confused right now - maybe someone of you can help me out of my confusion. My goal is to have a user profile with completely different properties than Did I misunderstood the goal of this user profile factory or is it just not that easy to change |
@yiev , UserProfile is now in @loopback/security as it is used by both @loopback/authentication and @loopback/authorization . https://github.com/strongloop/loopback-next/blob/master/packages/security/src/types.ts#L37 It extends a type called Principle which introduces
In UserProfile itself, So essentially, you can specify any fields you want. |
@yiev Thank you for following up the implementation in the auth modules! Right now the Let me copy the relevant definitions: /**
* Represent a user, an application, or a device
*/
export interface Principal {
/**
* Name/id
*/
[securityId]: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[attribute: string]: any;
}
/**
* The minimum set of attributes that describe a user.
*/
export interface UserProfile extends Principal {
// `email` and `name` are added to be identical with the
// `UserProfile` that previously was exported by `@loopback/authentication`
email?: string;
name?: string;
} It is not an empty interface but in terms of the flexibility to define custom fields, they doesn't differ a lot. The current |
Thank you two for your answers! So implementing my own user like this should do the job, right?
|
@yiev , almost.
Upon login with correct credentials (e.g. username and password or token) via authentication, the authentication framework would like to store as little information about the user on the request context in the binding SecurityBindings.USER in an object of type UserProfile. So you should have a class named This is why we are introducing a convenience function interface :
which developers can use to convert a generic user type |
@emonddr That's a good advice and I do understand the point to store only the needed information in the user profile. But in my case It makes it for me a bit easier just to have always all information in the By the way: It's really great to have such fast response from the developers. Thank you! 😄 |
How do i bound the AuthenticationBindings.USER_PROFILE_FACTORY in my application.ts? |
Suggestion
This is a follow-up story for PoC #3771
Use Cases
Allow the strategy adapter to add a user profile factory that converts the returned user from a passport strategy to the user profile.
Examples
See the background and example in PoC PR
Acceptance criteria
UserProfileFactory
and keyUSER_PROFILE_FACTORY
in@loopback/authentication
to help developers inject the factory wherever it'sneeded.
userProfileFactory
inStrategyAdapter
's constructor.The text was updated successfully, but these errors were encountered: