コード例 #1
0
        private ClaimsIdentity CreateClaimsIdentity(Token token)
        {
            var claims = new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, token.Username),
                new Claim(ClaimTypes.Name, token.Username),
                new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", token.Username),
                new Claim("urn:Custom:UserType", "AnonymousUser")
            };

            return new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
        }
コード例 #2
0
 public ActionResult TokenLogin(Token token)
 {
     token = GetTokenFromDatabase(token.Value);
     if (token != null)
     {
         AuthenticateWithToken(token);
         return RedirectToAction("Index", "Home");
     }
     return RedirectToAction("Login");
 }
コード例 #3
0
        private void AuthenticateWithToken(Token token)
        {
            ClaimsIdentity identity = CreateClaimsIdentity(token);

            Microsoft.Owin.Security.IAuthenticationManager authenticationManager =
                System.Web.HttpContext.Current.GetOwinContext().Authentication;

            authenticationManager.SignIn(identity);
        }