Skip to content

Instantly share code, notes, and snippets.

@ocap-kirk
Created February 21, 2019 17:45
Show Gist options
  • Save ocap-kirk/4f794b25b86e99568925ea55107271f1 to your computer and use it in GitHub Desktop.
Save ocap-kirk/4f794b25b86e99568925ea55107271f1 to your computer and use it in GitHub Desktop.
Okta PIV / CAC Sign-in Widget Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello!</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="/style.css">
<!-- import the webpage's javascript file -->
<script src="/script.js" defer></script>
<!-- Latest CDN production Javascript and CSS: 2.14.0 -->
<script
src="https://ok1static.oktacdn.com/assets/js/sdk/okta-signin-widget/2.14.0/js/okta-sign-in.min.js"
type="text/javascript"></script>
<link
href="https://ok1static.oktacdn.com/assets/js/sdk/okta-signin-widget/2.14.0/css/okta-sign-in.min.css"
type="text/css"
rel="stylesheet"/>
<!-- Theme file: Customize or replace this file if you want to override our default styles -->
<link
href="https://ok1static.oktacdn.com/assets/js/sdk/okta-signin-widget/2.14.0/css/okta-theme.css"
type="text/css"
rel="stylesheet"/>
<!-- <style>.primary-auth-form { display:none;}
.auth-divider{ display:none;}
</style> -->
</head>
<body>
<div id="widget-container"></div>
<script>
var signIn = new OktaSignIn({
baseUrl: 'https://tkirk.oktapreview.com',
customButtons: [{
title: 'PIV/CAC',
className: 'btn-customAuth',
click: function() {
// clicking on the button navigates to another page
window.location.href = 'https://tkirk.oktapreview.com/login/cert?fromURI=%2Fhome%2Ftkirkoktapreviewcom_localsamlsp_1%2F0oaj9g2i7rDpf1JKe0h7%2Falnj9g6cmzoZ9pvvb0h7';
}
}]
});
signIn.renderEl({
el: '#widget-container'
}, function success(res) {
if (res.status === 'SUCCESS') {
console.log('Do something with this sessionToken', res.session.token);
res.session.setCookieAndRedirect('/home/tkirkoktapreviewcom_localsamlsp_1/0oaj9g2i7rDpf1JKe0h7/alnj9g6cmzoZ9pvvb0h7');
} else {
// The user can be in another authentication state that requires further action.
// For more information about these states, see:
// https://github.com/okta/okta-signin-widget#rendereloptions-success-error
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment