【发布时间】:2017-09-22 16:03:47
【问题描述】:
我正在使用 C# 开发一个 Web 应用程序,该应用程序在注册期间使用 2 因素身份验证。我已经使用 Nexmo 的 API 尝试过 2FA。它工作得很好。我所要做的就是调用他们的 API 并指定“收件人”号码。代码如下:
public ActionResult Start(string to)
{
var start = NumberVerify.Verify(new NumberVerify.VerifyRequest
{
number = to,
brand = "NexmoQS"
});
Session["requestID"] = start.request_id;
return View();
}
现在,我决定试试 Twilio。我遇到了 Authy 和它的过程。我找到了他们的 2FA API here。但我不明白应该在哪里输入 Nexmo 中指定的“收件人”号码。我是初学者并使用 .NET(C#) 代码 sn-p。这是代码sn-p。请帮助我配置此代码,就像我在 Nexmo 中所做的那样。
public static async Task VerifyPhoneAsync()
{
// Create client
var client = new HttpClient();
// Add authentication header
client.DefaultRequestHeaders.Add("X-Authy-API-Key", AuthyAPIKey);
// https://api.authy.com/protected/$AUTHY_API_FORMAT/phones/verification/check?phone_number=$USER_PHONE&country_code=$USER_COUNTRY&verification_code=$VERIFY_CODE
HttpResponseMessage response = await client.GetAsync("https://api.authy.com/protected/json/phones/verification/check?phone_number=5558675309&country_code=1&verification_code=3043");
// Get the response content.
HttpContent responseContent = response.Content;
// Get the stream of the content.
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
// Write the output.
Console.WriteLine(await reader.ReadToEndAsync());
}
}
他们已经给出了他们的 api here 的 cURL 实现,请帮我在 C# 中配置它。
curl "http://api.authy.com/protected/json/users/new?api_key=d57d919d11e6b221c9bf6f7c882028f9" \
-d user[email]="user@domain.com" \
-d user[cellphone]="317-338-9302" \
-d user[country_code]="54"
【问题讨论】:
-
运行这段代码会发生什么?有什么错误吗?您从 API 得到什么响应?
-
我无法运行它。它说找不到
AuthyAPIKey -
这是什么意思?
-
你从哪里得到
AuthyAPIKey?如果是这样有什么重要性?您是否从某处复制粘贴代码?你看过这个 API 的文档了吗? -
AuthyAPIKey在我发布的 api 代码中作为函数client.DefaultRequestHeaders.Add("X-Authy-API-Key", AuthyAPIKey);的参数存在。我假设我必须用我拥有的 api 密钥替换字符串,但AuthyAPIKey仍然给出找不到它的错误。另外我应该在哪里输入收件人的号码?
标签: c# asp.net .net curl twilio