-
Hi folks, hi Luís, Two possibilities i could think of: 1)extend documentation add section token creation: "adding payload consisting of associative array with multiple key value pairs" please add a best practice example to the documentation on how to add payload data in the form of an associative array (consisting of multiple key => value pairs) on token creation. Right now i have came up with a solution such as: Example:
OR Alternative for future jwt releases 2)maybe it makes sense to provide a new function in future lcobucci/jwt releases to $config->builder()->withClaims($array) to deal with associative array payload data? Maybe not the user but lcobucci/jwt should take care about to proper handle the adding of multiple payload data on token creation? i hope this helps others with similar issues as i had. Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Yeah, your "actual token creation" should look like this:
Why building the builder inside the loop? If you don't build it because the array is empty, all following code accessing the |
Beta Was this translation helpful? Give feedback.
-
And in fact your example data array is quite complex, carrying the notion that "additional_data" seems to be requiring special treatment anyways. I don't know why the data has to be json_encoded base64'd, but this isn't something this library would do for you. So we are effectively talking about who is doing the loop: Your code, or the libraries code, because the implementation of
|
Beta Was this translation helpful? Give feedback.
-
Thank you very much @SvenRtbg for pointing this out. getting the builder object before foreach() is the way to go. I have tried this before and did not succeed, sure there was another issue in my code i have not been aware of... closing. sidenote: Thank you! |
Beta Was this translation helpful? Give feedback.
-
Two side-comments:
|
Beta Was this translation helpful? Give feedback.
Yeah, your "actual token creation" should look like this:
Why building the builder inside the loop? If you don't build it because the array is empty, all following code accessing the
$builder
to get the token will fail because the builder hasn't been created.