public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] {"*"}); var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>(); var user = await userManager.FindAsync(context.UserName, context.Password); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); identity.AddClaim(new Claim("sub", context.UserName)); foreach (var role in user.Roles) { identity.AddClaim(new Claim(ClaimTypes.Role, role)); } var sessionGuid = _sessionManager.BuildSessionManagerClient(Guid.Empty).OpenSession(context.UserName); identity.AddClaim(new Claim("gameSession", sessionGuid.ToString())); context.Validated(identity); //context.Request.Context.Authentication.SignIn(cookiesIdentity); }
public void InitializeSession(string userName) { if (HttpContext.Current.Session["SessionGuid"] == null) { if (!_simpleUserManager.Exists(userName)) { _simpleUserManager.Create(new UserData { Login = userName }); } HttpContext.Current.Session["SessionGuid"] = _sessionManagerClient.BuildSessionManagerClient(Guid.Empty).OpenSession(userName); } InitializeGameContext((Guid)HttpContext.Current.Session["SessionGuid"]); }