Beispiel #1
0
        /// <summary>
        /// Get the claims about the active user and return the user model
        /// Authentication used jwt authentication
        /// </summary>
        /// <typeparam name="TUser"></typeparam>
        /// <param name="jsRuntime"></param>
        /// <returns></returns>
        public static async Task <TUser> GetUserAsync <TUser>(IJSRuntime jsRuntime) where TUser : new ()
        {
            string data = await jsRuntime.GetUserDataAsync();

            if (string.IsNullOrEmpty(data))
            {
                return(new TUser());
            }
            else
            {
                string token = await jsRuntime.GetUserTokenAsync();

                string        key        = token.Split('.')[2];
                Cipher.Secret e          = new Cipher.Secret(key);
                string        jsonString = await e.DecriptAsync(data);

                return(JsonSerializer.Deserialize <TUser>(jsonString));
            }
        }