Exemplo n.º 1
0
        public static String Issue(String data, TimeSpan validFor, Int32 maxUses)
        {
            if (data.Length > 90)
                throw new ArgumentException("The data for the token cannot be longer than 90 characters");

            DateTime issued = UtcDateTime.Now;
            DateTime expires = issued.Add(validFor);

            data = Guid.NewGuid().ToString() + "," + data + "," + expires.Ticks;

            TextEncryption crypto = new TextEncryption(GooeyConfigManager.TokenEncyrptionKey);
            String result = crypto.Encrypt(data);

            SecurityToken token = new SecurityToken();
            token.Token = result;
            token.Issued = issued;
            token.Expires = expires;
            token.Uses = 0;
            token.MaxUses = maxUses;

            SaveToDatabase(token);

            return result;
        }
Exemplo n.º 2
0
 private static void SaveToDatabase(SecurityToken token)
 {
     SecurityTokenDao dao = new SecurityTokenDao();
     using (Transaction tx = new Transaction())
     {
         dao.Save<SecurityToken>(token);
         tx.Commit();
     }
 }