コード例 #1
0
        /// <summary>
        /// Gets the access token of an user that associate with a session and return a JSON Web Token
        /// </summary>
        /// <param name="user">The user identity</param>
        /// <param name="key">The key used to encrypt and sign</param>
        /// <param name="onCompleted">The action to run when the processing is completed</param>
        /// <param name="hashAlgorithm">The hash algorithm used to hash and sign (md5, sha1, sha256, sha384, sha512, ripemd/ripemd160, blake128, blake/blake256, blake384, blake512)</param>
        /// <returns>A JSON Web Token that presents the access token</returns>
        public static string GetAccessToken(this User user, BigInteger key, Action <JObject> onCompleted = null, string hashAlgorithm = "BLAKE256")
        {
            var roles = $"{SystemRole.All}{(user.ID.IsValidUUID() ? $",{SystemRole.Authenticated}" : "")}{(user.IsSystemAdministrator ? $",{SystemRole.SystemAdministrator}" : "")}";

            return(UserExtentions.GetAccessToken(user.ID, user.SessionID, roles.ToList().Concat(user.Roles ?? new List <string>()), user.Privileges, key, onCompleted, hashAlgorithm));
        }
コード例 #2
0
 /// <summary>
 /// Gets the authenticate token of an user and return a JSON Web Token
 /// </summary>
 /// <param name="user">The identity of an user</param>
 /// <param name="encryptionKey">The passphrase that used to encrypt data using AES</param>
 /// <param name="signKey">The passphrase that used to sign and verify the token</param>
 /// <param name="onCompleted">The action to run when the processing is completed</param>
 /// <returns>A JSON Web Token that presents the authenticate token</returns>
 public static string GetAuthenticateToken(this User user, string encryptionKey, string signKey, Action <JObject> onCompleted = null)
 => UserExtentions.GetAuthenticateToken(user.ID, user.SessionID, encryptionKey, signKey, onCompleted);