/Api

Authenticator (2FA)

The Authenticator (2FA devices) API allows you to generate one-time passwords (OTPs) and virtual security devices, for the purpose of testing authentication systems.

Retrieve one-time password

Retrieves the one-time password for a given base32-encoded secret.

Body parameters

  • Name
    sharedSecret
    Type
    string
    Required
    required
    Description
    The base32-encoded shared secret to generate a one-time password for.
Postman iconInsomnia icon
POST /api/devices/otp
curl \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{"sharedSecret":"ONSWG4TFOQYTEMY="}' \
  -u api:YOUR_API_KEY \
  https://mailosaur.com/api/devices/otp
const sharedSecret = 'ONSWG4TFOQYTEMY=';
const currentOtp = await mailosaur.devices.otp(sharedSecret);

console.log(currentOtp.code); // "564214"
const sharedSecret = 'ONSWG4TFOQYTEMY=';

cy.mailosaurGetDeviceOtp(sharedSecret)
  .then(currentOtp => {
      cy.log(currentOtp.code); // "564214" 
  });
shared_secret = "ONSWG4TFOQYTEMY="
current_otp = mailosaur.devices.otp(shared_secret)

print current_otp.code # "564214"
String sharedSecret = "ONSWG4TFOQYTEMY=";
String currentOtp = mailosaur.devices().otp(sharedSecret);

System.out.println(currentOtp.code); // "564214"
var sharedSecret = "ONSWG4TFOQYTEMY=";
var currentOtp = mailosaur.Devices.Otp(sharedSecret);

Console.WriteLine(currentOtp.code); // "564214"
shared_secret = 'ONSWG4TFOQYTEMY='
current_otp = mailosaur.devices.otp(shared_secret)

print(current_otp.code) # "564214"
$sharedSecret = 'ONSWG4TFOQYTEMY=';
$currentOtp = $mailosaur->devices->otp($sharedSecret);

print($currentOtp->code); // "564214"
sharedSecret := "ONSWG4TFOQYTEMY="

currentOtp := m.Devices.Otp(sharedSecret)
fmt.Println(currentOtp.Code) // "564214"
{
  "code": "123456",
  "expires": "2022-01-01T00:00:00Z"
}

List all devices

Returns a list of your virtual security devices.

Postman iconInsomnia icon
GET /api/devices
curl \
  -u api:YOUR_API_KEY \
  https://mailosaur.com/api/devices
const result = await mailosaur.devices.list();
console.log(result.items[0].name); // "Example"
cy.mailosaurListDevices().then(result => {
  cy.log(result.items[0].name); // "Example"
});
result = mailosaur.devices.list()
print result.items[0].name # "Example"
DeviceListResult result = mailosaur.devices().list();
var result = mailosaur.Devices.List();
Console.WriteLine(result.Items[0].Name); // "Example"
result = mailosaur.devices.list()
print(result.items[0].name) # "Example"
$result = $mailosaur->devices->all();
print($result->items[0]->name); // "Example"
result := m.Devices.List()
fmt.Println(result.Items[0].Name) // "Example"
[
    {
        "id": "abcd1234",
        "name": "Device name"
    }
]

Create a device

Creates a new virtual security device and returns it.

Body parameters

  • Name
    name
    Type
    string
    Required
    required
    Description
    A name for the virtual device.
  • Name
    sharedSecret
    Type
    string
    Required
    required
    Description
    The base32-encoded shared secret to generate a one-time password for.
Postman iconInsomnia icon
POST /api/devices
curl \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{"name":"Example","sharedSecret":"ONSWG4TFOQYTEMY="}' \
  -u api:YOUR_API_KEY \
  https://mailosaur.com/api/devices
await mailosaur.devices.create({
  name: 'Example',
  sharedSecret: 'ONSWG4TFOQYTEMY='
});
cy.mailosaurCreateDevice({
  name: 'Example',
  sharedSecret: 'ONSWG4TFOQYTEMY='
});
name = "Example"
shared_secret = "ONSWG4TFOQYTEMY="
options = DeviceCreateOptions(name, shared_secret)

mailosaur.devices.create(options)
DeviceCreateOptions options = new DeviceCreateOptions();
options.withName("Example")
  .withSharedSecret("ONSWG4TFOQYTEMY=");

mailosaur.devices().create(options);
mailosaur.Devices.Create(new DeviceCreateOptions()
  {
      Name = "Example",
      SharedSecret = "ONSWG4TFOQYTEMY="
  }
);
options = Mailosaur::Models::DeviceCreateOptions.new()
options.name = 'Example'
options.shared_secret = 'ONSWG4TFOQYTEMY='

mailosaur.devices.create(options)
$options = new DeviceCreateOptions();
$options->name = 'Example';
$options->sharedSecret = 'ONSWG4TFOQYTEMY=';

$mailosaur->devices->create($options);
m.Devices.Create(&DeviceCreateOptions{
  Name:         "Example",
  SharedSecret: "ONSWG4TFOQYTEMY=",
})
{
    "id": "abcd1234",
    "name": "My device"
}

Retrieve OTP for an existing device

Retrieves the current one-time password for an existing virtual security device. Simply supply the unique identifier for the required device.

Path parameters

  • Name
    id
    Type
    string
    Required
    required
    Description
    The identifier of the device to be retrieved.
Postman iconInsomnia icon
GET /api/devices/:id/otp
curl \
  -u api:YOUR_API_KEY \
  https://mailosaur.com/api/devices/DEVICE_ID/otp
const currentOtp = await mailosaur.devices.otp('DEVICE_ID');
console.log(currentOtp.code); // "564214"
cy.mailosaurGetDeviceOtp('DEVICE_ID')
  .then(currentOtp => {
      cy.log(currentOtp.code); // "564214" 
  });
current_otp = mailosaur.devices.otp("DEVICE_ID")
print current_otp.code # "564214"
String currentOtp = mailosaur.devices().otp("DEVICE_ID");
System.out.println(currentOtp.code); // "564214"
var currentOtp = mailosaur.Devices.Otp("DEVICE_ID");
Console.WriteLine(currentOtp.code); // "564214"
current_otp = mailosaur.devices.otp('DEVICE_ID')
print(current_otp.code) # "564214"
$currentOtp = $mailosaur->devices->otp('DEVICE_ID');
print($currentOtp->code); // "564214"
currentOtp := m.Devices.Otp("DEVICE_ID")
fmt.Println(currentOtp.Code) // "564214"
{
    "code": "123456",
    "expires": "2022-01-01T00:00:00Z"
}

Delete a device

Permanently deletes a device. This operation cannot be undone.

Path parameters

  • Name
    id
    Type
    string
    Required
    required
    Description
    The identifier of the device to be deleted.
Postman iconInsomnia icon
DELETE /api/devices/:id
curl \
  -X DELETE \
  -u api:YOUR_API_KEY \
  https://mailosaur.com/api/devices/DEVICE_ID
await mailosaur.devices.del('DEVICE_ID');
cy.mailosaurDeleteDevice('DEVICE_ID');
mailosaur.devices.delete("DEVICE_ID")
mailosaur.devices().delete("DEVICE_ID");
mailosaur.Devices.Delete("DEVICE_ID");
mailosaur.devices.delete('DELETE_ID')
$mailosaur->devices->delete('DEVICE_ID');
m.Devices.Delete("DEVICE_ID")