Exemplo n.º 1
0
        public async override Task <ClaimsPrincipal> CreateAsync(AppUser user)
        {
            var principal = await base.CreateAsync(user);

            ((ClaimsIdentity)principal.Identity).AddClaims(_claimsFactory.GetClaims(user).ToArray());

            return(principal);
        }
Exemplo n.º 2
0
        public string GetJWToken(AppUser user, DateTime accessExpires, string installationId)
        {
            var now    = DateTime.UtcNow;
            var claims = _claimsFactory.GetClaims(user);

            claims.Add(new Claim(JwtRegisteredClaimNames.Jti, NonceGenerator()));
            claims.Add(new Claim(JwtRegisteredClaimNames.Iat, new DateTimeOffset(now).ToUniversalTime().ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64));

            // Create the JWT and write it to a string
            var jwt = new JwtSecurityToken(
                issuer: _tokenOptions.Issuer,
                audience: _tokenOptions.Audience,
                claims: claims,
                notBefore: now,
                expires: accessExpires,
                signingCredentials: _tokenOptions.SigningCredentials);

            return(new JwtSecurityTokenHandler().WriteToken(jwt));
        }
Exemplo n.º 3
0
        public async Task <SignInResult> SignIn(string schema, AuthenticationProperties properties, params ClaimsIdentity[] identities)
        {
            SignInResult result     = new SignInResult();
            ForClaims    idenConfig = new ForClaims(_claimsFactory.GetClaims(), ForClaims.ExternalCookie);

            //---加入驗證邏輯---
            if (true)
            {
                await _context.Authentication.SignOutAsync(schema);

                await _context.Authentication.SignInAsync(schema, new ForPrincipal(idenConfig), properties);

                //_context.User = new ForPrincipal(idenConfig);
                result.Succeeded = true;
            }
            else
            {
                result.Succeeded = false;
            }
            return(result);
        }