I set up Elsa Workflows Core in an ASP.NET Core app, with authentication for HTTP requests.
I have an HttpEndpoint
activity, authentication is enforced, but I can't see any way to obtain the user's identity within the workflow.
The HttpContext
object doesn't seem to be available. I can get the HttpRequestModel
using GetInput()
, but HttpRequestModel
doesn't contain this information.
I'm using Microsoft AD authentication, but the question applies to any auth scheme.
If you are using dependency injection and running in a ASP.NET Core app, simply use constructor injection to get at IHttpContextAccessor
.
class YourClass
{
public YourClass(IHttpContextAccessor httpContext)
// ...
}
However this tightly couples your class with the HTTP context. You could create a view around it to return the things you need:
interface IUserAccessor
{
User User { get; }
}
class HttpContextUserAccessor : IUserAccessor
{
public YourClass(IHttpContextAccessor httpContext) //...
public User User { get; } // implement using httpContext
}
class YourClass
{
public YourClass(IUserAccessor userAccessor)
// ...
}
Also, it looks like Elsa has this pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With