コード例 #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));
        }