Skip to content

Cascade OTP in C#

Connect Cascade via HttpClient: send and verify OTP.

On this page
  1. Installation
  2. Init + send
  3. Verify

Cascade provides a REST API. Below is a practical minimum in C# with the HttpClient client.

Set OTP_API_TOKEN and OTP_API_DOMAIN in your backend environment. Set OTP_API_DOMAIN to the domain bound to the key, such as example.kz. Send the 4- or 6-digit code the user entered as a string. The verification examples read it from OTP_CODE.

Useful links: API, send, verify, examples, FAQ, pricing, documentation.

Installation

dotnet add package System.Net.Http.Json

An official Cascade NuGet package may not exist.

Init + send

using var http = new HttpClient { BaseAddress = new Uri("https://cascade.kz/api/") };
http.DefaultRequestHeaders.Authorization =
    new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("OTP_API_TOKEN"));
http.DefaultRequestHeaders.Accept.ParseAdd("application/json");
http.DefaultRequestHeaders.Add("X-Cascade-Client-Domain", Environment.GetEnvironmentVariable("OTP_API_DOMAIN"));

var send = await http.PostAsJsonAsync("otp/send", new { phone = "77001234567", purpose = "verification" });
var sendBody = await send.Content.ReadFromJsonAsync<JsonElement>();

Verify

var verify = await http.PostAsJsonAsync("otp/verify", new { phone = "77001234567", code = Environment.GetEnvironmentVariable("OTP_CODE"), purpose = "verification" });

Check the success property. See API, documentation, use-cases.