@microsoft/teamsapp-cli
Version:
Teams Toolkit CLI is a text-based command line interface that can help scaffold, validate, and deploy applications for Microsoft Teams from the terminal or a CI/CD process.
69 lines (64 loc) • 2.54 kB
HTML
<!--This file is auto generated by Teams Toolkit to provide you instructions and reference code to implement single sign on. -->
<!--This file is used during the Teams Bot authentication flow to assist with retrieval of the access token.-->
<!--If you're not familiar with this, do not alter or remove this file from your project.-->
<html>
<head>
<title>Login End Page</title>
<meta charset="utf-8" />
</head>
<body>
<script
src="https://res.cdn.office.net/teams-js/2.31.1/js/MicrosoftTeams.min.js"
integrity="sha384-ihAqYgEJz9hzEU+HaYodG1aTzjebC/wKXQi1nWKZG7OLAUyOL9ZrzD/SfZu79Jeu"
crossorigin="anonymous"
></script>
<div id="divError"></div>
<script type="text/javascript">
microsoftTeams.app.initialize().then(() => {
let hashParams = getHashParameters();
if (hashParams.get("error")) {
// Authentication failed
handleAuthError(hashParams.get("error"), hashParams);
} else if (hashParams.get("code")) {
// Get the stored state parameter and compare with incoming state
let expectedState = localStorage.getItem("state");
if (expectedState !== hashParams.get("state")) {
// State does not match, report error
handleAuthError("StateDoesNotMatch", hashParams);
} else {
microsoftTeams.authentication.notifySuccess();
}
} else {
// Unexpected condition: hash does not contain error or access_token parameter
handleAuthError("UnexpectedFailure", hashParams);
}
});
// Parse hash parameters into key-value pairs
function getHashParameters() {
let hashParams = new Map();
location.hash
.substr(1)
.split("&")
.forEach(function (item) {
let s = item.split("="),
k = s[0],
v = s[1] && decodeURIComponent(s[1]);
hashParams.set(k, v);
});
return hashParams;
}
// Show error information
function handleAuthError(errorType, errorMessage) {
const err = JSON.stringify({
error: encodeURIComponent(errorType),
message: encodeURIComponent(JSON.stringify(errorMessage)),
});
let para = document.createElement("p");
let node = document.createTextNode(err);
para.appendChild(node);
let element = document.getElementById("divError");
element.appendChild(para);
}
</script>
</body>
</html>