From 26eb87ccb7aa3d2521fc17551d6648a14f88fd17 Mon Sep 17 00:00:00 2001 From: cuqmbr Date: Tue, 19 Jul 2022 12:37:08 +0300 Subject: [PATCH] feat: add ability to use JWT to HttpClient --- Assets/_Scripts/Utilities/HttpClient.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Assets/_Scripts/Utilities/HttpClient.cs b/Assets/_Scripts/Utilities/HttpClient.cs index 27fe230..de430c7 100644 --- a/Assets/_Scripts/Utilities/HttpClient.cs +++ b/Assets/_Scripts/Utilities/HttpClient.cs @@ -6,6 +6,8 @@ using UnityEngine.Networking; public static class HttpClient { + private static string _jwt = ""; + public static async Task Get(string endpoint) { var getRequest = CreateRequest(endpoint, RequestType.GET); @@ -39,6 +41,11 @@ public static class HttpClient return JsonConvert.DeserializeObject(postRequest.downloadHandler.text); } + public static void SetJwt(string jwt) + { + _jwt = jwt; + } + private static UnityWebRequest CreateRequest(string path, RequestType type, object data = null) { var request = new UnityWebRequest(path, type.ToString()); @@ -51,6 +58,7 @@ public static class HttpClient request.downloadHandler = new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); + request.SetRequestHeader("Authorization", $"Bearer {_jwt}"); request.certificateHandler = new CertificateWhore();