Authy-Net 1.0.2

Another Implementation of the Twilio's Authy 2FA Api for .Net Framework

Install-Package Authy-Net -Version 1.0.2
dotnet add package Authy-Net --version 1.0.2
<PackageReference Include="Authy-Net" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Authy-Net --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Authy.Net

Build status

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("someone@email.com", "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("someone@email.com", "222-222-1122", 1);
Method 2:
...

// Creates a user with the given email, cell number, and country code
var response = client.AddNewUser("someone@email.com", "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("someone@email.com", "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": "someone@email.com",
  "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
}

Authy.Net

Build status

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("someone@email.com", "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("someone@email.com", "222-222-1122", 1);
Method 2:
...

// Creates a user with the given email, cell number, and country code
var response = client.AddNewUser("someone@email.com", "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("someone@email.com", "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": "someone@email.com",
  "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
}

Version History

Version Downloads Last updated
1.0.2 289 6/2/2018