Skip to content

Instantly share code, notes, and snippets.

@HomerJSimpson
Created March 10, 2023 04:38
Show Gist options
  • Save HomerJSimpson/9723c7ad8dfc03e17b4beac130825ab4 to your computer and use it in GitHub Desktop.
Save HomerJSimpson/9723c7ad8dfc03e17b4beac130825ab4 to your computer and use it in GitHub Desktop.
Look Ma no idp
<html>
<body class="flex-container">
<script src="https://accounts.google.com/gsi/client" async defer></script>
<div id="buttonDiv" class="flex-item"></div>
<pre id="stuff" class="flex-item"></pre>
</body>
</html>
import * as jwt_decode from "https://cdn.skypack.dev/[email protected]";
function handleCredentialResponse(response) {
console.log("Encoded JWT ID token: " + response.credential);
const $stuff = document.getElementById("stuff");
const jwt = jwt_decode.default(response.credential);
document.getElementById("buttonDiv").style.visibility = "hidden";
$stuff.innerText = JSON.stringify(jwt, null, "\t");
$stuff.innerText += `\n${new Date(jwt.exp * 1000)}`;
}
window.onload = function () {
google.accounts.id.initialize({
client_id:
"Webapp CLient ID",
callback: handleCredentialResponse
});
google.accounts.id.renderButton(
document.getElementById("buttonDiv"),
{ theme: "outline", size: "large" } // customization attributes
);
google.accounts.id.prompt(); // also display the One Tap dialog
};
.flex-container {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
align-items: flex-start;
}
.flex-item:nth-child(2) {
order: 0;
flex: 0 1 auto;
align-self: flex-end;
}
.flex-item:nth-child(3) {
order: 0;
flex: 0 1 auto;
align-self: auto;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment