-
Notifications
You must be signed in to change notification settings - Fork 4
Home
DuoAuth is used to make requests to the Duo Security REST API.
In order to use the service, you'll need to sign up for an account. Once it's been created, here's how to set up an Integration so you can use the REST API:
- Click on the "Integrations" item in the sidebar and click "New Application".
- For the Integration type, choose "REST API" and give it a name.
- Once it's created, click on its name to get to the detail page. Here's where you'll find the keys you'll need to access the API (integration key, secret key and the API hostname).
With everything set up correctly (Duo Security integration made on their site and duoauth.json
config made), validating a user's code is as easy as:
<?php
$user = new \DuoAuth\User();
if ($user->validateCode($code, 'username')){
echo "woot! They're valid!";
}
?>
In order to set the access tokens (integration/secret keys, API hostname) for the integrations, you'll need to create a duoauth.json
configuration file in your root directory. You can find an example in the repo:
{
"integrations": {
"admin": {
"secret": "your-secret-key",
"integration": "your-integration-key",
"hostname": "your-api-hostname"
},
"auth": {
"secret": "your-secret-key",
"integration": "your-integration-key",
"hostname": "your-api-hostname"
}
}
}
Without this file, you will no be able to connect to the Duo Security APIs. The tool reads this file internally and picks out the config settings based on what kind of Integration is specified for the object.
As with any web service, there'll be things that go wrong. The DuoAuth
class records these issues in its Error
class. If you get a false
or error returned from a method, you can call:
<?php
$errors = \DuoAuth\Error::get();
print_r($errors);
// or just one error
$error = \DuoAuth\Error::get($errorId);
?>
It can be used to set custom errors too:
<?php
\DuoAuth\Error::set('this is my message', 'my-custom-key');
?>