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

How to access User Context #29

Open
ghost opened this issue Apr 25, 2017 · 4 comments
Open

How to access User Context #29

ghost opened this issue Apr 25, 2017 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 25, 2017

Hello,

I would like to access my User Identity from any Handler, any ideas to do that?

@radu-matei
Copy link
Owner

What type of authentication are you using? Cookie authentication, bearer token?

I haven't had a chance to take a look at this, but any help would be appreciated. If I get any time I will take a look at this, it is among the priorities for this.

Thanks!

@ghost
Copy link
Author

ghost commented Apr 26, 2017

I use Cookie authentication.

My current workaround is to create a SuperSocket class:
`
public class SuperSocket
{
public WebSocket Socket
{
get;
set;
}
public ClaimsPrincipal User
{
get;
set;
}

    public SuperSocket(WebSocket socket, ClaimsPrincipal user)
    {
        Socket = socket;
        User = user;
    }
}

`

and in the Invoke method of the WebSocketManagerMiddleware class I instantiate my SuperSocket like that:
var superSocket = new SuperSocket(socket, context.User);

But I'm not sure if it's a good idea to proceed like that :/

@liddellj
Copy link

I just encountered the same requirement. My approach was to modify WebSocketHandler.ReceiveAsync to allow passing of the HttpContext, which allows access to a ClaimsPrincipal via HttpContext.User.

@hkosmidi
Copy link

hkosmidi commented Nov 7, 2017

Could you give us a sample of the ReceiveAsync?

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

No branches or pull requests

3 participants