Devices
The 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.
Parameters
Body parameters
sharedSecret
stringThe base32-encoded shared secret to generate a one-time password for.
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"
Response
{
"code": "123456",
"expires": "2022-01-01T00:00:00Z"
}
List all devices
Returns a list of your virtual security 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"
Response
[
{
"id": "abcd1234",
"name": "Device name"
}
]
Create a device
Creates a new virtual security device and returns it.
Parameters
Body parameters
name
stringA name for the virtual device.
sharedSecret
stringThe base32-encoded shared secret to generate a one-time password for.
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=",
})
Response
{
"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.
Parameters
Path parameters
id
stringThe identifier of the device to be retrieved.
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"
Response
{
"code": "123456",
"expires": "2022-01-01T00:00:00Z"
}
Delete a device
Permanently deletes a device. This operation cannot be undone.
Parameters
Path parameters
id
stringThe identifier of the device to be deleted.
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")