Skip to content

Instantly share code, notes, and snippets.

@sbrichardson
Last active September 27, 2016 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbrichardson/cf9273a8d3825487f066c52225563eba to your computer and use it in GitHub Desktop.
Save sbrichardson/cf9273a8d3825487f066c52225563eba to your computer and use it in GitHub Desktop.
Meteor Duo iFrame Template js
//basic function to process the response from Duo and route to another page. Param will be the HTML form component.
const processSubmit = function(form) {
// check to ensure correct parameter format
check(form, Match.Where(x => {
return x.nodeName === 'FORM';
}));
// get the input component from the form
const responseInput = form.elements.namedItem("sig_response");
// get the value of the input
const sig_response = responseInput && responseInput.value;
if (sig_response) {
// send the sign response to the server to process
Meteor.call('processDuoResponse', sig_response, (err, res) => {
if (err) {
console.log('err in processDuoResponse callback', err);
}
if (res) {
// if successful log a message and route to another page.
console.log('success login from duo');
FlowRouter.go('/app/main'); // replace with valid url to redirect to.
}
});
}
};
Template.loginAuthFrame.onRendered(function() {
// verify Duo is available on client
if (lo_.isObject(Duo)) {
// generate a sign request for the user on the server
Meteor.call('duoSignReq', (err, res) => {
if (err) {
console.log('err in duoSignReq callback', err);
}
if (res) {
// initialize the Duo iframe with signed request, this will load the auth options for the specific user.
Duo.init({
host: 'YOUR-API-HOSTNAME.duosecurity.com', //replace with your proper Duo api hostname from the Duo Application settings
sig_request: res,
submit_callback: processSubmit
});
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment