Authy-Net
1.0.2
dotnet add package Authy-Net --version 1.0.2
NuGet\Install-Package Authy-Net -Version 1.0.2
<PackageReference Include="Authy-Net" Version="1.0.2" />
paket add Authy-Net --version 1.0.2
#r "nuget: Authy-Net, 1.0.2"
// Install Authy-Net as a Cake Addin #addin nuget:?package=Authy-Net&version=1.0.2 // Install Authy-Net as a Cake Tool #tool nuget:?package=Authy-Net&version=1.0.2
Authy.Net
Another Implementation of the Twilio's Authy 2FA Api for .Net Framework
Creating a client
This following example will create a client which is necessary for calling the Authy API Endpoints
var client = new Authy.Net.Client("{AUTHY-PRODUCTION-KEY}");
Creating the client in test mode
var client = new Authy.Net.Client("{AUTHY-KEY}", true);
Creating a new user
There is two ways of creating a user.
Method 1:
This method requires that a instance of Authy.Net.Client
is initialized
// Creates a user with the given email, cell number, and country code
var user = Authy.Net.DataModels.User.CreateUser("[email protected]", "222-222-1122", 1);
Or in Net 4.5 or higher you can use the Async method
// Creates a user with the given email, cell number, and country code (awaitable)
var user = await Authy.Net.DataModels.User.CreateUserAsync("[email protected]", "222-222-1122", 1);
Method 2:
...
// Creates a user with the given email, cell number, and country code
var response = client.AddNewUser("[email protected]", "222-222-1122", 1);
// Then you can use the returned users AuthyID
Console.WriteLine(response.UserId);
Then the Async way
...
// Creates a user with the given email, cell number, and country code (awaitable)
var response = await client.AddNewUserAsync("[email protected]", "222-222-1122", 1);
// Then you can use the returned users AuthyID
Console.WriteLine(response.UserId);
Getting user info
When getting user info you need the AuthyID of the client you got from Creating the user
...
// Retrieve the UserStatusResponse from Authy
var status = client.GetUserStatus(1234567);
Console.WriteLine(JsonConvert.SerializeObject(status, Formatting.Indented));
Async method
...
// Retrieve the UserStatusResponse from Authy (awaitable)
var status = await client.GetUserStatusAsync(1234567);
Console.WriteLine(JsonConvert.SerializeObject(status, Formatting.Indented));
Response
{
"user_id": 0123456,
"user_confirmed": true,
"user_registered": true,
"user_cellphone": 4045,
"user_countrycode": 1,
"user_devices": [
"Android",
"Authy_Chrome",
"Chrome"
],
"message": "User status.",
"success": true
}
Removing a user
You can remove/unsubscribe a user from your application
Note: this could cause some issues if you subscribe and unsubscribe a user from your application that causes OneTouch push notification to fail on the Clients side. This issue is easily fixed by the client reinstalling the Authy client on their device
This should still be used if a user wants to unsubscribe from your app.
...
// Returns a GenericResponse that you can use the Success property to determine if the client was removed
var response = client.RemoveUser(0123456)
Async method
...
// Returns a GenericResponse that you can use the Success property to determine if the client was removed
var response = await client.RemoveUserAsync(0123456)
OneTouch Requests
OneTouch requests are used to notifications that are sent as Push notifications to the users device were the user has the option to Press approve or denied
Starting a OneTouch request
Utilizing the Authy.Net.DataModel.User
class
...
// The message that gets displayed to the user
var message = "Hello user, this is a test!"
// The details the get displayed to the user
var details = new Dictionary<string, string>()
{
["Hello"] = "World",
["Someother"] = "Data"
};
// The hidden extra details
var hiddendetails = new Dictionary<string, string>()
{
["IPAddress"] = "127.0.0.1",
["Other"] = "Info"
};
// Logo override
var logos = new Dictionary<string, string>()
{
["default"] = "https://i.imgur.com/C4htUmO.jpg",
["low"] = "https://i.imgur.com/C4htUmO.jpg",
["med"] = "https://i.imgur.com/C4htUmO.jpg",
["high"] = "https://i.imgur.com/C4htUmO.jpg"
};
var expire = TimeSpan.FromMinutes(5);
// Returns the uuid of the OneTouch request
// Async Method: `user.OneTouchRequestAsync`
var response = user.OneTouchRequest(message, expire, details, hiddendetails, logos);
Or you can utilize the client class
// The message that gets displayed to the user
var message = "Hello user, this is a test!"
// The details the get displayed to the user
var details = new Dictionary<string, string>()
{
["Hello"] = "World",
["Someother"] = "Data"
};
// The hidden extra details
var hiddendetails = new Dictionary<string, string>()
{
["IPAddress"] = "127.0.0.1",
["Other"] = "Info"
};
// Logo override
var logos = new Dictionary<string, string>()
{
["default"] = "https://i.imgur.com/C4htUmO.jpg",
["low"] = "https://i.imgur.com/C4htUmO.jpg",
["med"] = "https://i.imgur.com/C4htUmO.jpg",
["high"] = "https://i.imgur.com/C4htUmO.jpg"
};
var expire = TimeSpan.FromMinutes(5);
// Returns the ApprovalRequestResponse of the OneTouch request
// Async Method: `client.StartOneTouchRequestAsync`
var response = client.StartOneTouchRequest(0123456, message, expire, details, hiddendetails, logos);
Console.WriteLine(response.ApprovalUid);
Getting a OneTouch request status
...
var status = client.GetOneTouchStatus("{uuid-onetouch-request}");
Console.WriteLine(JsonConvert.SerializeObject(status, Formatting.Indented));
or the Async method
...
var status = await client.GetOneTouchStatusAsync("{uuid-onetouch-request}");
Console.WriteLine(JsonConvert.SerializeObject(status, Formatting.Indented));
Response
{
"_app_name": "AppName",
"_app_serial_id": 0123456885,
"_authy_id": 0123456,
"_user_email": "[email protected]",
"app_id": "appuuid",
"created_at": "2018-06-01T22:57:24+00:00",
"processed_at": "2018-06-01T22:57:42+00:00",
"seconds_to_expire": 180,
"status": "Approved",
"updated_at": "2018-06-01T22:57:42+00:00",
"user_id": "other_userid",
"uuid": "other_uuid",
"success": true
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Framework | net35 is compatible. net40 was computed. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 is compatible. net472 was computed. net48 was computed. net481 was computed. |
-
.NETCoreApp 2.0
- Newtonsoft.Json (>= 11.0.2)
- System.Net.Http (>= 4.3.3)
-
.NETFramework 3.5
- Newtonsoft.Json (>= 11.0.2)
-
.NETFramework 4.5
- Newtonsoft.Json (>= 11.0.2)
- System.Net.Http (>= 4.3.3)
-
.NETFramework 4.7.1
- Newtonsoft.Json (>= 11.0.2)
- System.Net.Http (>= 4.3.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.2 | 3,186 | 6/2/2018 |