Beispiel #1
0
        public static Token CheckPermitions(string authHeader, IDbConnection db)
        {
            if (authHeader.IsNullOrEmpty())
                return null;

            if (!authHeader.StartsWith("Bearer ", StringComparison.Ordinal))
                return null;

            Guid token;
            if (!Guid.TryParse(authHeader.Substring(7), out token))
                return null;

            var dbToken = db.FirstOrDefaultById<Token>(token);
            if (dbToken == null || dbToken.ExpiresIn < DateTime.Now)
                return null;

            dbToken.ExpiresIn = DateTime.Now + TimeSpan.FromDays(7);
            db.Update(dbToken);
            return dbToken;
        }