Skip to content

Commit

Permalink
Review and Updating sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Harikrishnan-MSFT committed Oct 30, 2023
1 parent a1b16f9 commit be6c36c
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
microsoftTeams.app.initialize().then(() => {
getAuthToken();
});
});
// Get face book client side token.
function getAuthToken() {
microsoftTeams.app.initialize().then(() => {
localStorage.removeItem("auth.error");
let code = getHashParameters();
let key = "auth.result";
localStorage.setItem(key, JSON.stringify({
idToken: code,
}));
localStorage.removeItem("auth.error");
let code = getHashParameters();
let key = "auth.result";
localStorage.setItem(key, JSON.stringify({
idToken: code,
}));
microsoftTeams.authentication.notifySuccess(key);
});
microsoftTeams.authentication.notifySuccess(key);
}
// Parse hash parameters into key-value pairs
Expand Down
2 changes: 0 additions & 2 deletions samples/app-complete-auth/nodejs/views/AuthTab.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
});
});
microsoftTeams.app.initialize().then(() => {
ssoAuthentication = () => {
getClientSideToken()
.then((clientSideToken) => {
Expand All @@ -50,7 +49,6 @@
}
});
}
});
function getClientSideToken() {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion samples/app-complete-auth/nodejs/views/fb-auth.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
crossorigin="anonymous"></script>
<script>
microsoftTeams.app.initialize().then(() => {
});
localStorage.removeItem("auth.error");
let code = getHashParameters();
let key = "auth.result";
Expand All @@ -24,7 +25,6 @@
var code = url.searchParams.get("code");
return code;
}
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

<script>
microsoftTeams.app.initialize().then(() => {
function submit()
{
microsoftTeams.authentication.notifySuccess('PopUpSignInAuthenticationSuccess');
}
});
function submit()
{
microsoftTeams.authentication.notifySuccess('PopUpSignInAuthenticationSuccess');
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
(async function() {
'use strict';
microsoftTeams.app.initialize().then(() => {
await microsoftTeams.app.initialize();
// Get auth token
// Ask Teams to get us a token from AAD
function getClientSideToken() {
Expand Down Expand Up @@ -86,5 +86,4 @@
console.log(`Error from web service: ${error}`);
}
});
});
})();
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@
<title>Screen</title>
<script>
$(document).ready(function () {
$('input[type="radio"]').click(function () {
var inputValue = $(this).attr("value");
var targetBox = $("." + inputValue);
$(".desc").not(targetBox).hide();
$(targetBox).show();
microsoftTeams.app.initialize().then(() => {
$('input[type="radio"]').click(function () {
var inputValue = $(this).attr("value");
var targetBox = $("." + inputValue);
$(".desc").not(targetBox).hide();
$(targetBox).show();
});
});
});
microsoftTeams.app.initialize().then(() => {
var token = localStorage.getItem("accessToken");
var username = "";
var userId = "";
Expand Down Expand Up @@ -171,7 +172,6 @@
return true;
};
});
</script>
</head>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ let accessToken;

function login() {
microsoftTeams.app.initialize().then(() => {
});
getClientSideToken()
.then((clientSideToken) => {
return getServerSideToken(clientSideToken);
})
.catch((error) => {
console.log(error);
if (error === "invalid_grant") {
// Display in-line button so user can consent
$("#divError").text("Error while exchanging for Server token - invalid_grant - User or admin consent is required.");
$("#divError").show();
$("#consent").show();
$("#adaptiveBtn").hide();
} else {
// Display in-line button so user can consent
$("#divError").text("Error while exchanging for Server token - invalid_grant - User or admin consent is required.");
$("#divError").show();
$("#consent").show();
$("#adaptiveBtn").hide();
.then((clientSideToken) => {
return getServerSideToken(clientSideToken);
})
.catch((error) => {
console.log(error);
if (error === "invalid_grant") {
// Display in-line button so user can consent
$("#divError").text("Error while exchanging for Server token - invalid_grant - User or admin consent is required.");
$("#divError").show();
$("#consent").show();
$("#adaptiveBtn").hide();
} else {
// Display in-line button so user can consent
$("#divError").text("Error while exchanging for Server token - invalid_grant - User or admin consent is required.");
$("#divError").show();
$("#consent").show();
$("#adaptiveBtn").hide();

// Something else went wrong
}
});
// Something else went wrong
}
});
}

Expand Down
20 changes: 10 additions & 10 deletions samples/msgext-search-sso-config/nodejs/public/searchSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@
<script type="text/javascript">

microsoftTeams.app.initialize().then(() => {
function onSubmit() {
var newSettings = [];
});

function onSubmit() {
var newSettings = [];

var options = document.getElementsByName("includeInSearch");
var options = document.getElementsByName("includeInSearch");

for (var i = 0; i < options.length; i++) {
if (options[i].checked) {
newSettings.push(options[i].value);
}
for (var i = 0; i < options.length; i++) {
if (options[i].checked) {
newSettings.push(options[i].value);
}

microsoftTeams.authentication.notifySuccess(JSON.stringify(newSettings));
}
});

microsoftTeams.authentication.notifySuccess(JSON.stringify(newSettings));
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
<script src="https://code.jquery.com/jquery-3.1.1.js" crossorigin="anonymous"></script>
<script src="https://res.cdn.office.net/teams-js/2.0.0/js/MicrosoftTeams.min.js" crossorigin="anonymous"></script>
<script type="text/javascript">
microsoftTeams.app.initialize().then(() => {
console.log(localStorage.getItem("displayName"));
window.onload = function () {
document.getElementById("greetingMsgSetup").innerHTML = `Welcome ${localStorage.getItem("displayName")}...`;
};
});
console.log(localStorage.getItem("displayName"));
window.onload = function () {
document.getElementById("greetingMsgSetup").innerHTML = `Welcome ${localStorage.getItem("displayName")}...`;
};
</script>
90 changes: 46 additions & 44 deletions samples/tab-people-picker/nodejs/views/tab.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,58 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#defaultSelected").hide();
$("#allMemberOfOrganisationSelected").hide();
$("#singleSelected").hide();
microsoftTeams.app.initialize().then(() => {
$("#defaultSelected").hide();
$("#allMemberOfOrganisationSelected").hide();
$("#singleSelected").hide();
});
});
let aadId;
microsoftTeams.app.initialize().then(() => {
microsoftTeams.app.getContext().then(function (context) {
aadId = context.user.id
})
microsoftTeams.app.getContext().then(function (context) {
aadId = context.user.id
})
// People picker api call.
function selectPeople(e, setSelected, openOrgWideSearchInChatOrChannel, singleSelect) {
var id = $(e.currentTarget).attr('data-id');
if (setSelected == "default") {
setSelected = [aadId];
}
microsoftTeams.people.selectPeople({ setSelected: setSelected, openOrgWideSearchInChatOrChannel: openOrgWideSearchInChatOrChannel, singleSelect: singleSelect }).then((people) => {
if (people) {
let peopleData = JSON.stringify(people);
if (id == "default") {
$("#defaultSelected").empty();
$("#defaultSelected").append("Selected member: " + peopleData)
$("#defaultSelected").show();
}
if (id == "singleSelect") {
$("#singleSelected").empty();
$("#singleSelected").append("Selected member: " + peopleData)
$("#singleSelected").show();
}
if (id == "allMemberOfOrganisation") {
$("#allMemberOfOrganisationSelected").empty();
$("#allMemberOfOrganisationSelected").append("Selected member: " + peopleData)
$("#allMemberOfOrganisationSelected").show();
}
if (id == "defaultSelect") {
$("#defaultMemberSelected").empty();
$("#defaultMemberSelected").append("Selected member: " + peopleData)
$("#defaultMemberSelected").show();
}
}
});
function selectPeople(e, setSelected, openOrgWideSearchInChatOrChannel, singleSelect) {
var id = $(e.currentTarget).attr('data-id');
if (setSelected == "default") {
setSelected = [aadId];
}
});
microsoftTeams.people.selectPeople({ setSelected: setSelected, openOrgWideSearchInChatOrChannel: openOrgWideSearchInChatOrChannel, singleSelect: singleSelect }).then((people) => {
if (people) {
let peopleData = JSON.stringify(people);
if (id == "default") {
$("#defaultSelected").empty();
$("#defaultSelected").append("Selected member: " + peopleData)
$("#defaultSelected").show();
}
if (id == "singleSelect") {
$("#singleSelected").empty();
$("#singleSelected").append("Selected member: " + peopleData)
$("#singleSelected").show();
}
if (id == "allMemberOfOrganisation") {
$("#allMemberOfOrganisationSelected").empty();
$("#allMemberOfOrganisationSelected").append("Selected member: " + peopleData)
$("#allMemberOfOrganisationSelected").show();
}
if (id == "defaultSelect") {
$("#defaultMemberSelected").empty();
$("#defaultMemberSelected").append("Selected member: " + peopleData)
$("#defaultMemberSelected").show();
}
}
});
}
</script>
<style>
#mainDiv {
Expand Down
2 changes: 0 additions & 2 deletions samples/tab-sso/nodejs/src/client/scripts/ssoDemo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
function ssoAuth() {
'use strict';
microsoftTeams.app.initialize().then(() => {

// 1. Get auth token
// Ask Teams to get us a token from AAD
Expand Down Expand Up @@ -136,5 +135,4 @@ function ssoAuth() {
console.error(error);
});
});
});
}
18 changes: 9 additions & 9 deletions samples/tab-stage-view/nodejs/server/views/sampleTab.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
</script>
<script>
microsoftTeams.app.initialize().then(() => {
function createLink() {
var appId = "<%-microsoftAppId%>";
var baseUrl = "<%-baseUrl%>";
// Passing the values and encoding the url while implementing the deeplink from tab
let url = "https://teams.microsoft.com/l/stage/"+appId+"/0?context={\"contentUrl\":\""+baseUrl+"/content\",\"websiteUrl\":\""+baseUrl+"/content\",\"name\":\"DemoStageView\"}";
alert("URL - " + url);
microsoftTeams.app.openLink(url);
};
});
function createLink() {
var appId = "<%-microsoftAppId%>";
var baseUrl = "<%-baseUrl%>";
// Passing the values and encoding the url while implementing the deeplink from tab
let url = "https://teams.microsoft.com/l/stage/"+appId+"/0?context={\"contentUrl\":\""+baseUrl+"/content\",\"websiteUrl\":\""+baseUrl+"/content\",\"name\":\"DemoStageView\"}";
alert("URL - " + url);
microsoftTeams.app.openLink(url);
};
</script>
</head>

Expand Down

0 comments on commit be6c36c

Please sign in to comment.