Skip to content

Commit

Permalink
refactored changes for json encoded put and post rest requests
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktHensen committed Aug 6, 2023
1 parent a6d6db7 commit cc913f0
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public GitHubOidcProvider() : base()
authorizationEndpoint = "https://github.com/login/oauth/authorize";
tokenEndpoint = "https://github.com/login/oauth/access_token";
userInfoEndpoint = "https://api.github.com/user";
RestConnector = new JsonEncodeUnityWebRequestRestConnector();
}


Expand All @@ -40,8 +41,7 @@ public override async Task<string> GetAccessTokenFromCodeAsync(string code, stri

string uri = tokenEndpoint + $"?client_id={ClientData.ClientId}" +
$"&redirect_uri={redirectUri}" + $"&client_secret={ClientData.ClientSecret}&code={code}&grant_type=authorization_code";
GitHubWebRequestRestConnector rc = new GitHubWebRequestRestConnector();
WebResponse<string> response = await rc.PostAsync(uri, "");
WebResponse<string> response = await RestConnector.PostAsync(uri, "");

if (response.Successful)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ public interface IRestConnector
{
Task<WebResponse<string>> GetAsync(string uri, Dictionary<string, string> headers = null);

Task<WebResponse<string>> PostAsync(string uri, string postData, Dictionary<string, string> headers = null);
Task<WebResponse<string>> PostAsync(string uri, string postJson, Dictionary<string, string> headers = null);

Task<WebResponse<string>> PostAsync(string uri, byte[] postData, Dictionary<string, string> headers = null);

Task<WebResponse<string>> PutAsync(string uri, string postData, Dictionary<string, string> headers = null);
Task<WebResponse<string>> PutAsync(string uri, string putJson, Dictionary<string, string> headers = null);

Task<WebResponse<string>> DeleteAsync(string uri, Dictionary<string, string> headers = null);
Task<WebResponse<string>> PutAsync(string uri, byte[] putData, Dictionary<string, string> headers = null);

Task<WebResponse<string>> DeleteAsync(string uri, Dictionary<string, string> headers = null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using i5.Toolkit.Core.Utilities.Async;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.Networking;

namespace i5.Toolkit.Core.Utilities
{
public class JsonEncodeUnityWebRequestRestConnector : UnityWebRequestRestConnector
{
public override async Task<WebResponse<string>> PostAsync(string uri, string postJson, Dictionary<string, string> headers = null)
{
byte[] data = new UTF8Encoding().GetBytes(postJson);
return await PostPutDataAsync(uri, "POST", data, "application/json", headers);
}

public override async Task<WebResponse<string>> PutAsync(string uri, string postData, Dictionary<string, string> headers = null)
{
byte[] data = new UTF8Encoding().GetBytes(postData);
return await PostPutDataAsync(uri, "PUT", data, "application/json", headers);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cc913f0

Please sign in to comment.