Skip to content

Commit

Permalink
Annict認証系を非同期に silane#7
Browse files Browse the repository at this point in the history
  • Loading branch information
noriokun4649 committed Feb 18, 2021
1 parent 86034b1 commit 76ff505
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace TVTComment.Model.TwitterUtils.AnnictUtils
{
Expand All @@ -30,7 +31,7 @@ public Uri GetAuthorizeUri()
return new(@$"{HOST}{endpoint}?client_id={ClientId}&response_type={ResponseType}&redirect_uri={RedirectUri}&scope={Scope}");
}

public string GetToken(string token)
public async Task<string> GetTokenAsync(string token)
{
const string endpoint = "oauth/token";
using var web = new WebClient();
Expand All @@ -42,7 +43,7 @@ public string GetToken(string token)
postBodyParameters.Add("code", token);
try
{
var vs = web.UploadValues(@$"{HOST}{endpoint}", postBodyParameters);
var vs = await web.UploadValuesTaskAsync(@$"{HOST}{endpoint}", postBodyParameters);
var json = JsonDocument.Parse(Encoding.UTF8.GetString(vs)).RootElement;
return json.GetProperty("access_token").GetString();
}
Expand Down

0 comments on commit 76ff505

Please sign in to comment.