Ejemplo n.º 1
0
        private async static Task <RevokedToken> _findToken(string login)
        {
            using (ModelsDBContext ctx = new ModelsDBContext())
            {
                RevokedToken revokedToken = await ctx.RevokedTokens.FirstOrDefaultAsync(t => t.Name == login);

                return(revokedToken);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Logs a <see cref="ConceptionDevisWS.Models.User"/> out.
 /// </summary>
 /// <param name="principal">the user's security identity</param>
 /// <remarks>
 /// This is not fully \htmlonly <accronym title="REpresentational State Transfer">REST</accronym>\endhtmlonly compliant, but it's usual.
 /// </remarks>
 public async static Task Logout(IPrincipal principal)
 {
     using (ModelsDBContext ctx = new ModelsDBContext())
     {
         RevokedToken revokedToken = new RevokedToken {
             Name = principal.Identity.Name
         };
         ctx.RevokedTokens.Add(revokedToken);
         await ctx.SaveChangesAsync();
     }
 }
Ejemplo n.º 3
0
        private async static Task _removeLogout(string login)
        {
            using (ModelsDBContext ctx = new ModelsDBContext())
            {
                RevokedToken seekedToken = await _findToken(login);

                if (seekedToken != null)
                {
                    ctx.Entry(seekedToken).State = EntityState.Deleted;
                    await ctx.SaveChangesAsync();
                }
            }
        }
Ejemplo n.º 4
0
        public async Task Revoke(string jti, string userId)
        {
            var tokens = await GetRevokedTokens();

            RevokedToken revokedToken = new RevokedToken
            {
                JTI    = jti,
                UserId = userId
            };

            if (!tokens.Contains(revokedToken))
            {
                tokens.Add(revokedToken);

                string json = JsonConvert.SerializeObject(tokens.ToArray());
                File.WriteAllText(revokedTokensPath, json);
            }
        }