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

Restore user credentials in HttpBackgroundJob #14329

Merged
merged 10 commits into from
Mar 26, 2024

Conversation

hyzx86
Copy link
Contributor

@hyzx86 hyzx86 commented Sep 14, 2023

use httpContextAccessor.HttpContext.User.Clone(); to set new HttpContext.User

This PR is submitted in order to start the workflow asynchronously in the script, because this will create a new http context, which will make it impossible to retrieve user information

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 14, 2023

Hi @jtkech ,I use these changes to work well in my code.
What do you think of this implementation?

@hishamco hishamco requested a review from jtkech September 14, 2023 13:52
Copy link
Member

@Piedone Piedone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain scenarios where you used this?

hyzx86 and others added 3 commits March 22, 2024 10:20
…ckgroundJob.cs

Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
…ckgroundJob.cs

Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
@hyzx86 hyzx86 requested a review from Piedone March 22, 2024 02:32
hyzx86 and others added 2 commits March 23, 2024 23:23
@Piedone
Copy link
Member

Piedone commented Mar 26, 2024

Just to confirm: are you done?

@hyzx86 hyzx86 requested a review from Piedone March 26, 2024 01:44
@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 26, 2024

Just to confirm: are you done?

Yes, please review it ,thanks!

@Piedone Piedone merged commit b1726ba into OrchardCMS:main Mar 26, 2024
4 checks passed
@sebastienros
Copy link
Member

Should it be done directly in shellContext.CreateHttpContext() maybe optionally as other callers of this method could have the same problem?

@Piedone
Copy link
Member

Piedone commented Mar 26, 2024

Not really, because you don't always have an actual HTTP request. This is about executing something after a real HTTP request, but with a different HttpContext, and thus a user can exist. In e.g. background tasks, there's no HTTP request and thus can be no user. Out of the four callers of this method, only HttpBackgroundJob needs this:

image

@hyzx86 hyzx86 deleted the Restore_user_credentials branch June 13, 2024 06:24
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

Successfully merging this pull request may close these issues.

3 participants