Created
February 13, 2020 04:09
-
-
Save kirk-marple/9429bb53a969fd2b5f2c0c6fc6d61da6 to your computer and use it in GitHub Desktop.
Verify Authy one-time token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task<bool> VerifyAuthyTokenAsync(ILogger logger, IConfiguration configuration, string authyId, string token) | |
{ | |
var apiKey = configuration.GetSection("AuthySettings")?["ApiKey"]; | |
if (String.IsNullOrEmpty(apiKey)) | |
throw new InvalidOperationException("Invalid Authy API key."); | |
using (var client = new HttpClient()) | |
{ | |
client.DefaultRequestHeaders.Add("X-Authy-API-Key", apiKey); | |
HttpResponseMessage response = await client.GetAsync($"https://api.authy.com/protected/json/verify/{token}/{authyId}"); | |
var unauthorized = (response.StatusCode == HttpStatusCode.Unauthorized); | |
var body = await response.Content.ReadAsStringAsync(); | |
logger?.LogInformation($"Recognized {(unauthorized ? "unauthorized" : "authorized")} token."); | |
logger?.LogDebug(body); | |
return !unauthorized; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment