[英]verify code authy with restsharp
I use the next piece of code to ask for a code to for a 2fa (two factor authentication) and works well: 我使用下一段代码来请求2fa(两因素身份验证)的代码,并且运行良好:
private async void TwilioSMS(object sender, EventArgs e)
{
RestSharp.RestClient client = new RestSharp.RestClient("https://api.authy.com/protected/json/phones/verification");
RestSharp.RestRequest request = new RestSharp.RestRequest("start", RestSharp.Method.POST);
numcheck = Numero.Text.Trim();
request.AddHeader("Content-Type", "application/json");
request.RequestFormat = RestSharp.DataFormat.Json;
string este = "{\"api_key\":\"" + apikey + "\",\"via\":\"sms\"," + "\"country_code\":52," + "\"phone_number\":"+numcheck + ",\"locale\":\"es\"}";
request.AddParameter("text/json", este, RestSharp.ParameterType.RequestBody);
RestSharp.IRestResponse response = await client.ExecuteTaskAsync(request);
respuesta = response.Content;
Console.WriteLine(respuesta);
}
But when I try to make the verification with the next piece of code: 但是,当我尝试使用下一段代码进行验证时:
private async void VerifCode(object sender, EventArgs e)
{
try
{
if (numcheck == string.Empty) { numcheck = Numero.Text.Trim(); }
RestSharp.RestClient client = new RestSharp.RestClient("https://api.authy.com/protected/json/phones/verification");
RestSharp.RestRequest request = new RestSharp.RestRequest("check", RestSharp.Method.GET);
request.AddHeader("Content-Type", "application/json");
request.RequestFormat = RestSharp.DataFormat.Json;
string este = "{\"api_key\":\"" + apikey + "\",\"country_code\":52," + "\"phone_number\":" + numcheck + ",\"verification_code\":" + Confirmation.Text.Trim() + "}";
request.AddParameter("text/json", este, RestSharp.ParameterType.RequestBody);
RestSharp.IRestResponse response = await client.ExecuteTaskAsync(request);
respuesta = response.Content;
Console.WriteLine(numcheck);
Console.WriteLine(response.Content);
var listo = respuesta.Split(new string[] { "\"success\":" }, StringSplitOptions.RemoveEmptyEntries)[1];
if (listo.Contains("true"))
{
await DisplayAlert("Código correcto", "El código es correcto", "OK");
}
else
{
await DisplayAlert("Código incorrecto", "El código es incorrecto o no ha sido mandado", "OK");
}
}
catch { await DisplayAlert("Código incorrecto", "El código es incorrecto o no ha sido mandado", "OK"); }
}
I get the next error: 我收到下一个错误:
{"error_code":"60001","message":"Invalid API key","errors":{"message":"Invalid API key"},"success":false}
I use the same api key for both, why the error happens? 两者都使用相同的api键,为什么会发生错误?
Twilio developer evangelist here. Twilio开发人员布道者在这里。
When making a call to api.authy.com/protected/json/phones/verification/check
the request should be a GET
request. 拨打
api.authy.com/protected/json/phones/verification/check
,请求应为GET
请求。 You have made a GET
request, however you passed the parameters as JSON in the body of the request. 您已经发出
GET
请求,但是在请求正文中将参数作为JSON传递了。 When making a GET
request you do not pass a body, so the Authy API is not reading them. 发出
GET
请求时,您不会传递主体,因此Authy API不会读取它们。 The parameters should be included as query string parameters in the URL and your API key should be set in the X-Authy-API-Key
header. 该参数应作为查询字符串参数包含在URL中,并且您的API密钥应在
X-Authy-API-Key
标头中设置。 See the curl example here for more detail . 有关更多详细信息,请参见此处的curl示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.