-
Notifications
You must be signed in to change notification settings - Fork 12
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
user.data populated on a user.registration event isn't available in a populate access token lamda for the first created access token #1545
Comments
@BugShooter if I understand the issue. you are doing this:
If that is correct, this is working as designed. This event can be configured as transactional, this means that if your webhook fails to return a 200 status code, we do not create the user registration. In order to accomplish that - this whole process takes place inside of a single transaction. So any changes made outside of this transaction are not visible within an open transaction that was started before any other changes were made. You could use the The only way that I can think of to ensure you get add a custom attribute to the user data during the user create process is to make an HTTP request in the JWT populate lambda to retrieve the value and place it in the JWT. However this won't allow you to persist it in the JWT, so you'd still need to add it to the user eventually. One example may be:
HTTP requests are available in Lambdas beginning in 1.35.0 for Essentials and Enterprise licenses. |
This issue concerns me, as we had planned to do exactly the same thing as the OP. Your steps diverge from the OP in two ways:
Doesn't FA "await" (pseudocode) transaction {
await UserCreateHooks();
await UserCreateRegistrationHooks();
commit();
}
// User data should be available here?
await JwtPopulateLambda(); If this doesn't work, and it's not easy to change, I was wondering about the idea of webhooks being allowed to return data, that is then merged into the user/registration object before it is persisted?
Not sure if it would help in this case. (it may be useful for other webhooks as well) The only other option we would have is to store the FA user ID in our database, and use that to authenticate the user in our API, but I think it'd be preferable to use our own IDs. Your proposed solution will not work for us, as we don't have an Essentials plan. I hope another solution can be found soon. |
@glen-84 There are no current plans to have the await happen in the form you suggest, though it is an interesting solution. I haven't looked at that code path, but I know there are a lot of moving parts in the login process. Unfortunately, it may be that FusionAuth isn't a good fit for your needs. That's a bummer, but we'd rather be transparent about it and let you find it out during a POC rather than during implementation :) . |
After spending a non-trivial amount of time evaluating Auth0, and the same with FusionAuth (including writing most of the refresh token/PKCE code that is not provided by the libraries), this is not an option for us (my boss would kill me 😝). FusionAuth ticks a lot of boxes (you've done great work), it's just these few things so far (#185, #1545, #1660, #1674) that would make our integration much smoother. For this particular issue, it seems like it'd be quite a common use case, and it's surprising to me that the Lambda doesn't have access to new user data when the webhooks are synchronous. Is the current flow documented anywhere? A clean solution to this would be nice, but if it's not possible then we'll be forced to store the user's FusionAuth ID in our database. |
I am still not sure I follow what is happening. Can you please provide a very specific set of ordered steps you are taking? For example, here is what I think you are doing, but please confirm and clarify with a lot of detail if I am not correct.
In step 3, when the user clicks the "Submit" button on the self-service registration form, FusionAuth performs the following steps in this order:
In this workflow, you want the JWT Populate to include any modifications to the user or registration made during the |
We want modifications in the synchronous (I would personally prefer to use NB. I have not yet tested this flow, as I had assumed that the OP had done so, but I will do so now, just to confirm. |
@glen-84 using The complete events are not asynchronous, they are just fired after the database transaction has occurred (and therefore More on that here: https://fusionauth.io/docs/v1/tech/events-webhooks/writing-a-webhook#calling-fusionauth-apis-in-webhooks The Please let us know if you test out the scenario. |
Okay, so I just tested this myself (twice), using the original instructions ( For the 2nd test, I added an artificial sleep of 2 seconds to both webhook EPs and it still worked. As for the OP, and assuming that this is not a timing issue, I can only assume one or more of:
As mentioned above, it does appear to work. Does the transaction wrap both user-create and user-registration-create, or are they separate transactions? i.e. (pseudocode): transaction {
await UserCreateHooks();
await UserRegistrationCreateHooks();
commit(); // save user and registration.
}
await JwtPopulateLambda(); vs: transaction {
await UserCreateHooks();
commit(); // save user.
}
transaction {
await UserRegistrationCreateHooks();
commit(); // save registration.
}
await JwtPopulateLambda(); If it's the latter, then the data would be available in
I just meant that FA won't wait for them to complete and fail the transaction if they fail.
That document literally says that this use case is supported 😄:
We'd want it to be transactional, otherwise a failure in the In summary:
For now, I might just continue storing and using the FA user IDs, since the 2-hook solution is not rock solid. |
Hmmm. Thanks for testing. I am afraid I might have been imprecise. What I meant is that modifying the user object from within the They are in two separate transactions, I believe, because they are not always an atomic item.
If you think it is worthwhile, please file a new issue suggesting it and we'll see what community support it garners.
This would be another great feature request. I can't really speak to whether we'd implement it, depends on community and customer feedback as well as engineering level of effort. We already allow webhooks to return a status code to indicate success or failure, so maybe a post processing step (including a lambda) would make sense. Please do file an issue.
That makes sense. For anyone else on this issue, I think the 2-hook solution will continue to work but I understand it may have side-effects. I feel like we can close this issue since you tested this (extensively!), so I'm going to do so. If someone else encounters this issue, please re-open. |
user.data populated on a user.registration event isn't available in a populate access token lamda for the first created access token
Description
I try add userId from custom database to JWT access token.
so I use FA's API in webhook to put customUserId in FA's user.data object successfuly
but this doesn't happen
Affects versions
1.31.0
Steps to reproduce
Precondition:
Steps to reproduce the behavior:
Expected behavior
I expect that user.data.customId will be available in the populate access token lamba on time when the first access token is generating
Additional context
I suppose that events should happens transactionaly in this way:
1 webhook on user.create finished and FA user entity exist
2 webhook on user.registration.create patch user.data object
3 only when step 2 is finished FA generate new access token and the populate access token lambda put info from user.data to the access token
The text was updated successfully, but these errors were encountered: