c# - Authenticate SignalR from MVC Controller -
i learning asp.net identity , signalr among other stuff. able create own authentication system using custom implementation of identity. trying authenticate user signalr before calling overridden onconnected.
after user gets authenticated using cookie authentication, [system.web.mvc.authorize]
attribute passes succesfully, while [microsoft.aspnet.signalr]
attribute tells me user has not authenticated yet.
//this authorize method: [httpget] public actionresult authorize() { authenticationmanager.signin(new claimsidentity(new claimsprincipal(user).claims.toarray(), "bearer")); return new emptyresult(); } //this cookieauthenticationoptions app.usecookieauthentication(new cookieauthenticationoptions { authenticationtype = defaultauthenticationtypes.applicationcookie, loginpath = new pathstring("/account/login"), provider = new cookieauthenticationprovider() }); //on hub public override task onconnected() { string username = context.user.identity.name; //user null? }
what missing here? have googled time , i'm not able find anything, not idea on how authenticate signalr.
most you're mapping signalr before authentication, must map signalr after authentication:
public void configuration(iappbuilder app) { app.usecookieauthentication(new cookieauthenticationoptions { authenticationtype = defaultauthenticationtypes.applicationcookie, loginpath = new pathstring("/home/index") }); //... app.mapsignalr(); }
Comments
Post a Comment