Dart Requires Chilkat v11.0.0+
Dart
Duo Auth API - Preauth
See more Duo Auth MFA Examples
The /preauth endpoint determines whether a user is authorized to log in, and (if so) returns the user's available authentication factors.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final integrationKey = 'DIMS3V5QDVG9J9ABRXC4';
final secretKey = 'HWVQ46nubLBxhnRlKddTltWIi3hL0fIQF2qTvLab';
final http = CkHttp();
http.accept = 'application/json';
// Use your own hostname here:
final url = 'https://api-a03782e1.duosecurity.com/auth/v2/preauth';
http.login = integrationKey;
http.password = secretKey;
final req = CkHttpRequest();
req.addParam('username', 'matt');
req.httpVerb = 'POST';
req.contentType = 'application/x-www-form-urlencoded';
final resp = CkHttpResponse();
try {
http.httpReq(url, req, resp);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('status code = ${resp.statusCode}');
final json = CkJsonObject();
json.load(resp.bodyStr);
json.emitCompact = false;
print(json.emit());
// Sample successful output:
// status code = 200
// {
// "response": {
// "devices": [
// {
// "capabilities": [
// "auto",
// "push",
// "sms",
// "mobile_otp"
// ],
// "device": "DP6GYVTQ5NK82BMR851F",
// "display_name": "iOS (XXX-XXX-1871)",
// "name": "",
// "number": "XXX-XXX-1871",
// "type": "phone"
// }
// ],
// "result": "auth",
// "status_msg": "Account is active"
// },
// "stat": "OK"
// }
// Sample code to parse the above JSON response..
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
var device = '';
var displayName = '';
var name = '';
var number = '';
var vType = '';
var j = 0;
var countJ = 0;
var strVal = '';
final responseResult = json.stringOf('response.result');
final responseStatusMsg = json.stringOf('response.status_msg');
final stat = json.stringOf('stat');
var i = 0;
final countI = json.sizeOfArray('response.devices');
while (i < countI) {
json.i = i;
device = json.stringOf('response.devices[i].device');
displayName = json.stringOf('response.devices[i].display_name');
name = json.stringOf('response.devices[i].name');
number = json.stringOf('response.devices[i].number');
vType = json.stringOf('response.devices[i].type');
j = 0;
countJ = json.sizeOfArray('response.devices[i].capabilities');
while (j < countJ) {
json.j = j;
strVal = json.stringOf('response.devices[i].capabilities[j]');
j++;
}
i++;
}
}