/// <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)); } }
/// <summary> /// Login request from a model user send /// Authentication used jwt authentication with token /// </summary> /// <typeparam name="TUser"></typeparam> /// <param name="jsRuntime"></param> /// <param name="user"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <bool> SignInAsync <TUser>(IJSRuntime jsRuntime, TUser user, string token) { bool result; try { string jsonString = JsonSerializer.Serialize <TUser>(user); string key = token.Split('.')[2]; Cipher.Secret e = new Cipher.Secret(key); string jsonData = await e.EncriptAsync(jsonString); await jsRuntime.SetAllDataAsync(jsonData, token); result = true; } catch (Exception ex) { string err = ex.Message; result = false; } return(result); }