@microsoft/teamsfx-core 1.7.0 → 1.7.1-alpha.8d048e1f1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/common/constants.d.ts +1 -1
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/constants.js +1 -1
- package/build/common/constants.js.map +1 -1
- package/build/common/projectSettingsHelper.d.ts.map +1 -1
- package/build/common/projectSettingsHelper.js +1 -1
- package/build/common/projectSettingsHelper.js.map +1 -1
- package/build/common/telemetry.d.ts +9 -0
- package/build/common/telemetry.d.ts.map +1 -1
- package/build/common/telemetry.js +9 -0
- package/build/common/telemetry.js.map +1 -1
- package/build/common/templates-config.json +2 -2
- package/build/common/tools.d.ts +1 -1
- package/build/common/tools.d.ts.map +1 -1
- package/build/common/tools.js +6 -5
- package/build/common/tools.js.map +1 -1
- package/build/core/FxCore.d.ts +2 -2
- package/build/core/FxCore.d.ts.map +1 -1
- package/build/core/FxCore.js +49 -11
- package/build/core/FxCore.js.map +1 -1
- package/build/core/environment.d.ts +1 -1
- package/build/core/environment.d.ts.map +1 -1
- package/build/core/environment.js +6 -1
- package/build/core/environment.js.map +1 -1
- package/build/core/error.d.ts +1 -0
- package/build/core/error.d.ts.map +1 -1
- package/build/core/error.js +5 -1
- package/build/core/error.js.map +1 -1
- package/build/core/middleware/aadManifestMigration.d.ts +3 -0
- package/build/core/middleware/aadManifestMigration.d.ts.map +1 -0
- package/build/core/middleware/aadManifestMigration.js +211 -0
- package/build/core/middleware/aadManifestMigration.js.map +1 -0
- package/build/core/middleware/consolidateLocalRemote.d.ts +2 -0
- package/build/core/middleware/consolidateLocalRemote.d.ts.map +1 -1
- package/build/core/middleware/consolidateLocalRemote.js +80 -51
- package/build/core/middleware/consolidateLocalRemote.js.map +1 -1
- package/build/core/middleware/questionModel.d.ts.map +1 -1
- package/build/core/middleware/questionModel.js +11 -2
- package/build/core/middleware/questionModel.js.map +1 -1
- package/build/core/question.d.ts +3 -1
- package/build/core/question.d.ts.map +1 -1
- package/build/core/question.js +22 -2
- package/build/core/question.js.map +1 -1
- package/build/plugins/resource/aad/plugin.d.ts +1 -0
- package/build/plugins/resource/aad/plugin.d.ts.map +1 -1
- package/build/plugins/resource/aad/plugin.js +54 -1
- package/build/plugins/resource/aad/plugin.js.map +1 -1
- package/build/plugins/resource/aad/utils/configs.d.ts.map +1 -1
- package/build/plugins/resource/aad/utils/configs.js +4 -1
- package/build/plugins/resource/aad/utils/configs.js.map +1 -1
- package/build/plugins/resource/apiconnector/checker.d.ts +2 -0
- package/build/plugins/resource/apiconnector/checker.d.ts.map +1 -0
- package/build/plugins/resource/apiconnector/checker.js +22 -0
- package/build/plugins/resource/apiconnector/checker.js.map +1 -0
- package/build/plugins/resource/apiconnector/config.d.ts +20 -0
- package/build/plugins/resource/apiconnector/config.d.ts.map +1 -0
- package/build/plugins/resource/apiconnector/config.js +5 -0
- package/build/plugins/resource/apiconnector/config.js.map +1 -0
- package/build/plugins/resource/apiconnector/constants.d.ts +15 -0
- package/build/plugins/resource/apiconnector/constants.d.ts.map +1 -1
- package/build/plugins/resource/apiconnector/constants.js +17 -1
- package/build/plugins/resource/apiconnector/constants.js.map +1 -1
- package/build/plugins/resource/apiconnector/depsHandler.d.ts +12 -0
- package/build/plugins/resource/apiconnector/depsHandler.d.ts.map +1 -0
- package/build/plugins/resource/apiconnector/depsHandler.js +66 -0
- package/build/plugins/resource/apiconnector/depsHandler.js.map +1 -0
- package/build/plugins/resource/apiconnector/envHandler.d.ts +2 -2
- package/build/plugins/resource/apiconnector/envHandler.d.ts.map +1 -1
- package/build/plugins/resource/apiconnector/envHandler.js +18 -24
- package/build/plugins/resource/apiconnector/envHandler.js.map +1 -1
- package/build/plugins/resource/apiconnector/errors.d.ts +13 -1
- package/build/plugins/resource/apiconnector/errors.d.ts.map +1 -1
- package/build/plugins/resource/apiconnector/errors.js +19 -7
- package/build/plugins/resource/apiconnector/errors.js.map +1 -1
- package/build/plugins/resource/apiconnector/index.d.ts.map +1 -1
- package/build/plugins/resource/apiconnector/index.js +1 -8
- package/build/plugins/resource/apiconnector/index.js.map +1 -1
- package/build/plugins/resource/apiconnector/plugin.d.ts +11 -2
- package/build/plugins/resource/apiconnector/plugin.d.ts.map +1 -1
- package/build/plugins/resource/apiconnector/plugin.js +179 -17
- package/build/plugins/resource/apiconnector/plugin.js.map +1 -1
- package/build/plugins/resource/apiconnector/questions.d.ts +23 -3
- package/build/plugins/resource/apiconnector/questions.d.ts.map +1 -1
- package/build/plugins/resource/apiconnector/questions.js +69 -22
- package/build/plugins/resource/apiconnector/questions.js.map +1 -1
- package/build/plugins/resource/apiconnector/result.d.ts +2 -1
- package/build/plugins/resource/apiconnector/result.d.ts.map +1 -1
- package/build/plugins/resource/apiconnector/result.js.map +1 -1
- package/build/plugins/resource/apiconnector/sampleHandler.d.ts +1 -1
- package/build/plugins/resource/apiconnector/sampleHandler.d.ts.map +1 -1
- package/build/plugins/resource/apiconnector/utils.d.ts +16 -20
- package/build/plugins/resource/apiconnector/utils.d.ts.map +1 -1
- package/build/plugins/resource/apiconnector/utils.js +72 -16
- package/build/plugins/resource/apiconnector/utils.js.map +1 -1
- package/build/plugins/resource/appstudio/appStudio.d.ts.map +1 -1
- package/build/plugins/resource/appstudio/appStudio.js +6 -5
- package/build/plugins/resource/appstudio/appStudio.js.map +1 -1
- package/build/plugins/resource/appstudio/manifestTemplate.d.ts.map +1 -1
- package/build/plugins/resource/appstudio/manifestTemplate.js +3 -3
- package/build/plugins/resource/appstudio/manifestTemplate.js.map +1 -1
- package/build/plugins/resource/appstudio/plugin.d.ts.map +1 -1
- package/build/plugins/resource/appstudio/plugin.js.map +1 -1
- package/build/plugins/resource/appstudio/v3/plugin.d.ts.map +1 -1
- package/build/plugins/resource/appstudio/v3/plugin.js +5 -0
- package/build/plugins/resource/appstudio/v3/plugin.js.map +1 -1
- package/build/plugins/resource/bot/azureOps.d.ts +0 -1
- package/build/plugins/resource/bot/azureOps.d.ts.map +1 -1
- package/build/plugins/resource/bot/azureOps.js +0 -28
- package/build/plugins/resource/bot/azureOps.js.map +1 -1
- package/build/plugins/resource/bot/clientFactory.d.ts +0 -5
- package/build/plugins/resource/bot/clientFactory.d.ts.map +1 -1
- package/build/plugins/resource/bot/clientFactory.js +1 -29
- package/build/plugins/resource/bot/clientFactory.js.map +1 -1
- package/build/plugins/resource/bot/constants.d.ts +0 -8
- package/build/plugins/resource/bot/constants.d.ts.map +1 -1
- package/build/plugins/resource/bot/constants.js +0 -8
- package/build/plugins/resource/bot/constants.js.map +1 -1
- package/build/plugins/resource/bot/errors.d.ts +0 -18
- package/build/plugins/resource/bot/errors.d.ts.map +1 -1
- package/build/plugins/resource/bot/errors.js +1 -38
- package/build/plugins/resource/bot/errors.js.map +1 -1
- package/build/plugins/resource/bot/functionsHostedBot/deployMgr.d.ts +1 -1
- package/build/plugins/resource/bot/functionsHostedBot/deployMgr.d.ts.map +1 -1
- package/build/plugins/resource/bot/functionsHostedBot/deployMgr.js +10 -4
- package/build/plugins/resource/bot/functionsHostedBot/deployMgr.js.map +1 -1
- package/build/plugins/resource/bot/functionsHostedBot/plugin.d.ts.map +1 -1
- package/build/plugins/resource/bot/functionsHostedBot/plugin.js +2 -6
- package/build/plugins/resource/bot/functionsHostedBot/plugin.js.map +1 -1
- package/build/plugins/resource/bot/plugin.d.ts.map +1 -1
- package/build/plugins/resource/bot/plugin.js +4 -1
- package/build/plugins/resource/bot/plugin.js.map +1 -1
- package/build/plugins/resource/frontend/resources/templateInfo.js +1 -1
- package/build/plugins/resource/frontend/resources/templateInfo.js.map +1 -1
- package/build/plugins/resource/sql/errors.d.ts.map +1 -1
- package/build/plugins/resource/sql/errors.js +29 -29
- package/build/plugins/resource/sql/errors.js.map +1 -1
- package/build/plugins/resource/sql/sqlClient.d.ts.map +1 -1
- package/build/plugins/resource/sql/sqlClient.js +2 -8
- package/build/plugins/resource/sql/sqlClient.js.map +1 -1
- package/build/plugins/solution/fx-solution/constants.d.ts +16 -2
- package/build/plugins/solution/fx-solution/constants.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/constants.js +19 -1
- package/build/plugins/solution/fx-solution/constants.js.map +1 -1
- package/build/plugins/solution/fx-solution/debug/util/launchNext.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/debug/util/launchNext.js +0 -26
- package/build/plugins/solution/fx-solution/debug/util/launchNext.js.map +1 -1
- package/build/plugins/solution/fx-solution/question.d.ts +3 -1
- package/build/plugins/solution/fx-solution/question.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/question.js +21 -7
- package/build/plugins/solution/fx-solution/question.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/deploy.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/deploy.js +14 -5
- package/build/plugins/solution/fx-solution/v2/deploy.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/executeUserTask.d.ts +2 -1
- package/build/plugins/solution/fx-solution/v2/executeUserTask.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/executeUserTask.js +121 -82
- package/build/plugins/solution/fx-solution/v2/executeUserTask.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/getQuestions.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/getQuestions.js +31 -22
- package/build/plugins/solution/fx-solution/v2/getQuestions.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/provision.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/provision.js +17 -6
- package/build/plugins/solution/fx-solution/v2/provision.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/utils.js +1 -1
- package/build/plugins/solution/fx-solution/v2/utils.js.map +1 -1
- package/package.json +3 -3
- package/resource/package.nls.json +91 -39
- package/resource/unify-config-change-logs.md +15 -0
- package/templates/core/README.md +1 -0
- package/templates/fallback/blazor-base.csharp.default.zip +0 -0
- package/templates/fallback/bot.csharp.default.zip +0 -0
- package/templates/fallback/bot.js.command-and-response.zip +0 -0
- package/templates/fallback/bot.js.default.zip +0 -0
- package/templates/fallback/bot.js.notification-function-base.zip +0 -0
- package/templates/fallback/bot.js.notification-restify.zip +0 -0
- package/templates/fallback/bot.js.notification-trigger-http.zip +0 -0
- package/templates/fallback/bot.js.notification-trigger-timer.zip +0 -0
- package/templates/fallback/bot.ts.command-and-response.zip +0 -0
- package/templates/fallback/bot.ts.default.zip +0 -0
- package/templates/fallback/bot.ts.notification-function-base.zip +0 -0
- package/templates/fallback/bot.ts.notification-restify.zip +0 -0
- package/templates/fallback/bot.ts.notification-trigger-http.zip +0 -0
- package/templates/fallback/bot.ts.notification-trigger-timer.zip +0 -0
- package/templates/fallback/bot.ts.notification.zip +0 -0
- package/templates/fallback/function-base.js.default.zip +0 -0
- package/templates/fallback/function-base.ts.default.zip +0 -0
- package/templates/fallback/function-triggers.js.HTTPTrigger.zip +0 -0
- package/templates/fallback/function-triggers.ts.HTTPTrigger.zip +0 -0
- package/templates/fallback/tab.csharp.default.zip +0 -0
- package/templates/fallback/tab.js.default.zip +0 -0
- package/templates/fallback/tab.js.m365.zip +0 -0
- package/templates/fallback/tab.js.non-sso.zip +0 -0
- package/templates/fallback/tab.ts.default.zip +0 -0
- package/templates/fallback/tab.ts.m365.zip +0 -0
- package/templates/fallback/tab.ts.non-sso.zip +0 -0
- package/templates/plugins/resource/aad/auth/bot/README.md +63 -0
- package/templates/plugins/resource/aad/auth/bot/js/public/auth-end.html +65 -0
- package/templates/plugins/resource/aad/auth/bot/js/public/auth-start.html +177 -0
- package/templates/plugins/resource/aad/auth/bot/js/sso/showUserInfo.js +19 -0
- package/templates/plugins/resource/aad/auth/bot/js/sso/ssoDialog.js +173 -0
- package/templates/plugins/resource/aad/auth/bot/js/sso/teamsSsoBot.js +55 -0
- package/templates/plugins/resource/aad/auth/bot/ts/public/auth-end.html +65 -0
- package/templates/plugins/resource/aad/auth/bot/ts/public/auth-start.html +177 -0
- package/templates/plugins/resource/aad/auth/bot/ts/sso/showUserInfo.ts +24 -0
- package/templates/plugins/resource/aad/auth/bot/ts/sso/ssoDialog.ts +182 -0
- package/templates/plugins/resource/aad/auth/bot/ts/sso/teamsSsoBot.ts +69 -0
- package/templates/plugins/resource/aad/auth/tab/README.md +49 -0
- package/templates/plugins/resource/aad/auth/tab/js/public/auth-end.html +58 -0
- package/templates/plugins/resource/aad/auth/tab/js/public/auth-start.html +57 -0
- package/templates/plugins/resource/aad/auth/tab/js/sso/GetUserProfile.jsx +34 -0
- package/templates/plugins/resource/aad/auth/tab/ts/public/auth-end.html +58 -0
- package/templates/plugins/resource/aad/auth/tab/ts/public/auth-start.html +57 -0
- package/templates/plugins/resource/aad/auth/tab/ts/sso/GetUserProfile.tsx +34 -0
- package/templates/plugins/resource/aad/manifest/aad.template.json +1 -14
- package/templates/plugins/resource/apiconnector/package.json +6 -0
- package/templates/plugins/resource/bot/bicep/botProvision.template.bicep +9 -0
- package/templates/plugins/resource/bot/bicep/funcHostedBotProvision.template.bicep +2 -0
- package/templates/plugins/resource/function/bicep/functionProvision.template.bicep +2 -0
- package/templates/plugins/resource/simpleauth/bicep/simpleAuthProvision.template.bicep +4 -0
- package/templates/plugins/resource/webapp/bicep/webappProvision.template.bicep +2 -0
- package/templates/core/README-auto-generated.md +0 -31
- package/templates/fallback/bot-msgext.csharp.default.zip +0 -0
- package/templates/fallback/bot-msgext.js.default.zip +0 -0
- package/templates/fallback/bot-msgext.ts.default.zip +0 -0
- package/templates/fallback/msgext.js.default.zip +0 -0
- package/templates/fallback/msgext.ts.default.zip +0 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<!--This file is used during the Teams Bot authentication flow to assist with retrieval of the access token.-->
|
|
2
|
+
<!--If you're not familiar with this, do not alter or remove this file from your project.-->
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>Login Start Page</title>
|
|
6
|
+
<meta charset="utf-8" />
|
|
7
|
+
</head>
|
|
8
|
+
|
|
9
|
+
<body>
|
|
10
|
+
<script type="text/javascript">
|
|
11
|
+
popUpSignInWindow();
|
|
12
|
+
|
|
13
|
+
async function popUpSignInWindow() {
|
|
14
|
+
// Generate random state string and store it, so we can verify it in the callback
|
|
15
|
+
let state = _guid();
|
|
16
|
+
localStorage.setItem("state", state);
|
|
17
|
+
localStorage.removeItem("codeVerifier");
|
|
18
|
+
var currentURL = new URL(window.location);
|
|
19
|
+
var clientId = currentURL.searchParams.get("clientId");
|
|
20
|
+
var tenantId = currentURL.searchParams.get("tenantId");
|
|
21
|
+
var loginHint = currentURL.searchParams.get("loginHint");
|
|
22
|
+
if (!loginHint) {
|
|
23
|
+
loginHint = "";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var scope = currentURL.searchParams.get("scope");
|
|
27
|
+
|
|
28
|
+
var originalCode = _guid();
|
|
29
|
+
var codeChallenge = await pkceChallengeFromVerifier(originalCode);
|
|
30
|
+
|
|
31
|
+
localStorage.setItem("codeVerifier", originalCode);
|
|
32
|
+
let queryParams = {
|
|
33
|
+
client_id: clientId,
|
|
34
|
+
response_type: "code",
|
|
35
|
+
response_mode: "fragment",
|
|
36
|
+
scope: scope,
|
|
37
|
+
redirect_uri: window.location.origin + "/auth-end.html",
|
|
38
|
+
nonce: _guid(),
|
|
39
|
+
login_hint: loginHint,
|
|
40
|
+
state: state,
|
|
41
|
+
code_challenge: codeChallenge,
|
|
42
|
+
code_challenge_method: "S256",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let authorizeEndpoint = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/authorize?${toQueryString(
|
|
46
|
+
queryParams
|
|
47
|
+
)}`;
|
|
48
|
+
window.location.assign(authorizeEndpoint);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Build query string from map of query parameter
|
|
52
|
+
function toQueryString(queryParams) {
|
|
53
|
+
let encodedQueryParams = [];
|
|
54
|
+
for (let key in queryParams) {
|
|
55
|
+
encodedQueryParams.push(key + "=" + encodeURIComponent(queryParams[key]));
|
|
56
|
+
}
|
|
57
|
+
return encodedQueryParams.join("&");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Converts decimal to hex equivalent
|
|
61
|
+
// (From ADAL.js: https://github.com/AzureAD/azure-activedirectory-library-for-js/blob/dev/lib/adal.js)
|
|
62
|
+
function _decimalToHex(number) {
|
|
63
|
+
var hex = number.toString(16);
|
|
64
|
+
while (hex.length < 2) {
|
|
65
|
+
hex = "0" + hex;
|
|
66
|
+
}
|
|
67
|
+
return hex;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Generates RFC4122 version 4 guid (128 bits)
|
|
71
|
+
// (From ADAL.js: https://github.com/AzureAD/azure-activedirectory-library-for-js/blob/dev/lib/adal.js)
|
|
72
|
+
function _guid() {
|
|
73
|
+
// RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or
|
|
74
|
+
// pseudo-random numbers.
|
|
75
|
+
// The algorithm is as follows:
|
|
76
|
+
// Set the two most significant bits (bits 6 and 7) of the
|
|
77
|
+
// clock_seq_hi_and_reserved to zero and one, respectively.
|
|
78
|
+
// Set the four most significant bits (bits 12 through 15) of the
|
|
79
|
+
// time_hi_and_version field to the 4-bit version number from
|
|
80
|
+
// Section 4.1.3. Version4
|
|
81
|
+
// Set all the other bits to randomly (or pseudo-randomly) chosen
|
|
82
|
+
// values.
|
|
83
|
+
// UUID = time-low "-" time-mid "-"time-high-and-version "-"clock-seq-reserved and low(2hexOctet)"-" node
|
|
84
|
+
// time-low = 4hexOctet
|
|
85
|
+
// time-mid = 2hexOctet
|
|
86
|
+
// time-high-and-version = 2hexOctet
|
|
87
|
+
// clock-seq-and-reserved = hexOctet:
|
|
88
|
+
// clock-seq-low = hexOctet
|
|
89
|
+
// node = 6hexOctet
|
|
90
|
+
// Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
|
91
|
+
// y could be 1000, 1001, 1010, 1011 since most significant two bits needs to be 10
|
|
92
|
+
// y values are 8, 9, A, B
|
|
93
|
+
var cryptoObj = window.crypto || window.msCrypto; // for IE 11
|
|
94
|
+
if (cryptoObj && cryptoObj.getRandomValues) {
|
|
95
|
+
var buffer = new Uint8Array(16);
|
|
96
|
+
cryptoObj.getRandomValues(buffer);
|
|
97
|
+
//buffer[6] and buffer[7] represents the time_hi_and_version field. We will set the four most significant bits (4 through 7) of buffer[6] to represent decimal number 4 (UUID version number).
|
|
98
|
+
buffer[6] |= 0x40; //buffer[6] | 01000000 will set the 6 bit to 1.
|
|
99
|
+
buffer[6] &= 0x4f; //buffer[6] & 01001111 will set the 4, 5, and 7 bit to 0 such that bits 4-7 == 0100 = "4".
|
|
100
|
+
//buffer[8] represents the clock_seq_hi_and_reserved field. We will set the two most significant bits (6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.
|
|
101
|
+
buffer[8] |= 0x80; //buffer[8] | 10000000 will set the 7 bit to 1.
|
|
102
|
+
buffer[8] &= 0xbf; //buffer[8] & 10111111 will set the 6 bit to 0.
|
|
103
|
+
return (
|
|
104
|
+
_decimalToHex(buffer[0]) +
|
|
105
|
+
_decimalToHex(buffer[1]) +
|
|
106
|
+
_decimalToHex(buffer[2]) +
|
|
107
|
+
_decimalToHex(buffer[3]) +
|
|
108
|
+
"-" +
|
|
109
|
+
_decimalToHex(buffer[4]) +
|
|
110
|
+
_decimalToHex(buffer[5]) +
|
|
111
|
+
"-" +
|
|
112
|
+
_decimalToHex(buffer[6]) +
|
|
113
|
+
_decimalToHex(buffer[7]) +
|
|
114
|
+
"-" +
|
|
115
|
+
_decimalToHex(buffer[8]) +
|
|
116
|
+
_decimalToHex(buffer[9]) +
|
|
117
|
+
"-" +
|
|
118
|
+
_decimalToHex(buffer[10]) +
|
|
119
|
+
_decimalToHex(buffer[11]) +
|
|
120
|
+
_decimalToHex(buffer[12]) +
|
|
121
|
+
_decimalToHex(buffer[13]) +
|
|
122
|
+
_decimalToHex(buffer[14]) +
|
|
123
|
+
_decimalToHex(buffer[15])
|
|
124
|
+
);
|
|
125
|
+
} else {
|
|
126
|
+
var guidHolder = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
|
127
|
+
var hex = "0123456789abcdef";
|
|
128
|
+
var r = 0;
|
|
129
|
+
var guidResponse = "";
|
|
130
|
+
for (var i = 0; i < 36; i++) {
|
|
131
|
+
if (guidHolder[i] !== "-" && guidHolder[i] !== "4") {
|
|
132
|
+
// each x and y needs to be random
|
|
133
|
+
r = (Math.random() * 16) | 0;
|
|
134
|
+
}
|
|
135
|
+
if (guidHolder[i] === "x") {
|
|
136
|
+
guidResponse += hex[r];
|
|
137
|
+
} else if (guidHolder[i] === "y") {
|
|
138
|
+
// clock-seq-and-reserved first hex is filtered and remaining hex values are random
|
|
139
|
+
r &= 0x3; // bit and with 0011 to set pos 2 to zero ?0??
|
|
140
|
+
r |= 0x8; // set pos 3 to 1 as 1???
|
|
141
|
+
guidResponse += hex[r];
|
|
142
|
+
} else {
|
|
143
|
+
guidResponse += guidHolder[i];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return guidResponse;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Calculate the SHA256 hash of the input text.
|
|
151
|
+
// Returns a promise that resolves to an ArrayBuffer
|
|
152
|
+
function sha256(plain) {
|
|
153
|
+
const encoder = new TextEncoder();
|
|
154
|
+
const data = encoder.encode(plain);
|
|
155
|
+
return window.crypto.subtle.digest("SHA-256", data);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Base64-urlencodes the input string
|
|
159
|
+
function base64urlencode(str) {
|
|
160
|
+
// Convert the ArrayBuffer to string using Uint8 array to convert to what btoa accepts.
|
|
161
|
+
// btoa accepts chars only within ascii 0-255 and base64 encodes them.
|
|
162
|
+
// Then convert the base64 encoded to base64url encoded
|
|
163
|
+
// (replace + with -, replace / with _, trim trailing =)
|
|
164
|
+
return btoa(String.fromCharCode.apply(null, new Uint8Array(str)))
|
|
165
|
+
.replace(/\+/g, "-")
|
|
166
|
+
.replace(/\//g, "_")
|
|
167
|
+
.replace(/=+$/, "");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Return the base64-urlencoded sha256 hash for the PKCE challenge
|
|
171
|
+
async function pkceChallengeFromVerifier(v) {
|
|
172
|
+
hashed = await sha256(v);
|
|
173
|
+
return base64urlencode(hashed);
|
|
174
|
+
}
|
|
175
|
+
</script>
|
|
176
|
+
</body>
|
|
177
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createMicrosoftGraphClient, TeamsFx } from "@microsoft/teamsfx";
|
|
2
|
+
import { TurnContext } from "botbuilder";
|
|
3
|
+
import { DialogTurnResult } from "botbuilder-dialogs";
|
|
4
|
+
|
|
5
|
+
export async function showUserInfo(
|
|
6
|
+
context: TurnContext,
|
|
7
|
+
ssoToken: string
|
|
8
|
+
): Promise<DialogTurnResult> {
|
|
9
|
+
await context.sendActivity("Retrieving user information from Microsoft Graph ...");
|
|
10
|
+
const teamsfx = new TeamsFx().setSsoToken(ssoToken);
|
|
11
|
+
const graphClient = createMicrosoftGraphClient(teamsfx, ["User.Read"]);
|
|
12
|
+
const me = await graphClient.api("/me").get();
|
|
13
|
+
if (me) {
|
|
14
|
+
await context.sendActivity(
|
|
15
|
+
`You're logged in as ${me.displayName} (${me.userPrincipalName})${
|
|
16
|
+
me.jobTitle ? `; your job title is: ${me.jobTitle}` : ""
|
|
17
|
+
}.`
|
|
18
|
+
);
|
|
19
|
+
} else {
|
|
20
|
+
await context.sendActivity("Could not retrieve profile information from Microsoft Graph.");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComponentDialog,
|
|
3
|
+
WaterfallDialog,
|
|
4
|
+
Dialog,
|
|
5
|
+
DialogTurnResult,
|
|
6
|
+
DialogSet,
|
|
7
|
+
DialogTurnStatus,
|
|
8
|
+
} from "botbuilder-dialogs";
|
|
9
|
+
import { ActivityTypes, Storage, tokenExchangeOperationName, TurnContext } from "botbuilder";
|
|
10
|
+
import { TeamsBotSsoPrompt, TeamsBotSsoPromptTokenResponse, TeamsFx } from "@microsoft/teamsfx";
|
|
11
|
+
import "isomorphic-fetch";
|
|
12
|
+
|
|
13
|
+
const DIALOG_NAME = "SSODialog";
|
|
14
|
+
const TEAMS_SSO_PROMPT_ID = "TeamsFxSsoPrompt";
|
|
15
|
+
const COMMAND_ROUTE_DIALOG = "CommandRouteDialog";
|
|
16
|
+
|
|
17
|
+
export class SsoDialog extends ComponentDialog {
|
|
18
|
+
private requiredScopes: string[];
|
|
19
|
+
private dedupStorage: Storage;
|
|
20
|
+
private dedupStorageKeys: string[] = [];
|
|
21
|
+
private commandMapping: Map<string, string | RegExp> = new Map<string, string | RegExp>();
|
|
22
|
+
|
|
23
|
+
constructor(dedupStorage: Storage, requiredScopes: string[]) {
|
|
24
|
+
super(DIALOG_NAME);
|
|
25
|
+
|
|
26
|
+
this.initialDialogId = COMMAND_ROUTE_DIALOG;
|
|
27
|
+
|
|
28
|
+
this.dedupStorage = dedupStorage;
|
|
29
|
+
this.dedupStorageKeys = [];
|
|
30
|
+
this.requiredScopes = requiredScopes;
|
|
31
|
+
|
|
32
|
+
const teamsFx = new TeamsFx();
|
|
33
|
+
const ssoDialog = new TeamsBotSsoPrompt(teamsFx, TEAMS_SSO_PROMPT_ID, {
|
|
34
|
+
scopes: this.requiredScopes,
|
|
35
|
+
endOnInvalidMessage: true,
|
|
36
|
+
});
|
|
37
|
+
this.addDialog(ssoDialog);
|
|
38
|
+
|
|
39
|
+
const commandRouteDialog = new WaterfallDialog(COMMAND_ROUTE_DIALOG, [
|
|
40
|
+
this.commandRouteStep.bind(this),
|
|
41
|
+
]);
|
|
42
|
+
this.addDialog(commandRouteDialog);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public addCommand(
|
|
46
|
+
commandId: string,
|
|
47
|
+
commandText: string | RegExp,
|
|
48
|
+
operation: (context: TurnContext, ssoToken: string) => Promise<DialogTurnResult>
|
|
49
|
+
): void {
|
|
50
|
+
const dialog = new WaterfallDialog(commandId, [
|
|
51
|
+
this.ssoStep.bind(this),
|
|
52
|
+
this.dedupStep.bind(this),
|
|
53
|
+
async (stepContext: any) => {
|
|
54
|
+
const tokenResponse: TeamsBotSsoPromptTokenResponse = stepContext.result;
|
|
55
|
+
const context: TurnContext = stepContext.context;
|
|
56
|
+
if (tokenResponse) {
|
|
57
|
+
await operation(context, tokenResponse.ssoToken);
|
|
58
|
+
} else {
|
|
59
|
+
await context.sendActivity("Failed to retrieve user token from conversation context.");
|
|
60
|
+
}
|
|
61
|
+
return await stepContext.endDialog();
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
if (this.commandMapping.has(commandId)) {
|
|
66
|
+
throw new Error(`Cannot add command. There is already a command with same id ${commandId}`);
|
|
67
|
+
}
|
|
68
|
+
this.commandMapping.set(commandId, commandText);
|
|
69
|
+
this.addDialog(dialog);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The run method handles the incoming activity (in the form of a DialogContext) and passes it through the dialog system.
|
|
74
|
+
* If no dialog is active, it will start the default dialog.
|
|
75
|
+
* @param {*} dialogContext
|
|
76
|
+
*/
|
|
77
|
+
public async run(context: TurnContext, accessor: any) {
|
|
78
|
+
const dialogSet = new DialogSet(accessor);
|
|
79
|
+
dialogSet.add(this);
|
|
80
|
+
|
|
81
|
+
const dialogContext = await dialogSet.createContext(context);
|
|
82
|
+
const results = await dialogContext.continueDialog();
|
|
83
|
+
if (results && results.status === DialogTurnStatus.empty) {
|
|
84
|
+
await dialogContext.beginDialog(this.id);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private async commandRouteStep(stepContext: any) {
|
|
89
|
+
const turnContext = stepContext.context as TurnContext;
|
|
90
|
+
|
|
91
|
+
// remove the mention of this bot
|
|
92
|
+
let text = TurnContext.removeRecipientMention(turnContext.activity);
|
|
93
|
+
if (text) {
|
|
94
|
+
// remove the line break
|
|
95
|
+
text = text.toLowerCase().replace(/\n|\r/g, "").trim();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const commandId = this.matchCommands(text);
|
|
99
|
+
if (commandId) {
|
|
100
|
+
return await stepContext.beginDialog(commandId);
|
|
101
|
+
}
|
|
102
|
+
return await stepContext.endDialog();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private async ssoStep(stepContext: any) {
|
|
106
|
+
return await stepContext.beginDialog(TEAMS_SSO_PROMPT_ID);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private async dedupStep(stepContext: any) {
|
|
110
|
+
const tokenResponse = stepContext.result;
|
|
111
|
+
// Only dedup after ssoStep to make sure that all Teams client would receive the login request
|
|
112
|
+
if (tokenResponse && (await this.shouldDedup(stepContext.context))) {
|
|
113
|
+
return Dialog.EndOfTurn;
|
|
114
|
+
}
|
|
115
|
+
return await stepContext.next(tokenResponse);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public async onEndDialog(context: TurnContext) {
|
|
119
|
+
const conversationId = context.activity.conversation.id;
|
|
120
|
+
const currentDedupKeys = this.dedupStorageKeys.filter((key) => key.indexOf(conversationId) > 0);
|
|
121
|
+
await this.dedupStorage.delete(currentDedupKeys);
|
|
122
|
+
this.dedupStorageKeys = this.dedupStorageKeys.filter((key) => key.indexOf(conversationId) < 0);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// If a user is signed into multiple Teams clients, the Bot might receive a "signin/tokenExchange" from each client.
|
|
126
|
+
// Each token exchange request for a specific user login will have an identical activity.value.Id.
|
|
127
|
+
// Only one of these token exchange requests should be processed by the bot. For a distributed bot in production,
|
|
128
|
+
// this requires a distributed storage to ensure only one token exchange is processed.
|
|
129
|
+
private async shouldDedup(context: TurnContext): Promise<boolean> {
|
|
130
|
+
const storeItem = {
|
|
131
|
+
eTag: context.activity.value.id,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const key = this.getStorageKey(context);
|
|
135
|
+
const storeItems = { [key]: storeItem };
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
await this.dedupStorage.write(storeItems);
|
|
139
|
+
this.dedupStorageKeys.push(key);
|
|
140
|
+
} catch (err) {
|
|
141
|
+
if (err instanceof Error && err.message.indexOf("eTag conflict")) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private getStorageKey(context: TurnContext): string {
|
|
150
|
+
if (!context || !context.activity || !context.activity.conversation) {
|
|
151
|
+
throw new Error("Invalid context, can not get storage key!");
|
|
152
|
+
}
|
|
153
|
+
const activity = context.activity;
|
|
154
|
+
const channelId = activity.channelId;
|
|
155
|
+
const conversationId = activity.conversation.id;
|
|
156
|
+
if (activity.type !== ActivityTypes.Invoke || activity.name !== tokenExchangeOperationName) {
|
|
157
|
+
throw new Error("TokenExchangeState can only be used with Invokes of signin/tokenExchange.");
|
|
158
|
+
}
|
|
159
|
+
const value = activity.value;
|
|
160
|
+
if (!value || !value.id) {
|
|
161
|
+
throw new Error("Invalid signin/tokenExchange. Missing activity.value.id.");
|
|
162
|
+
}
|
|
163
|
+
return `${channelId}/${conversationId}/${value.id}`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private matchCommands(text: string): string {
|
|
167
|
+
for (const command of this.commandMapping) {
|
|
168
|
+
const pattern: string | RegExp = command[1];
|
|
169
|
+
let matchResult: RegExpExecArray | boolean;
|
|
170
|
+
if (typeof pattern == "string") {
|
|
171
|
+
matchResult = text === pattern;
|
|
172
|
+
} else {
|
|
173
|
+
matchResult = pattern.exec(text);
|
|
174
|
+
}
|
|
175
|
+
if (matchResult) {
|
|
176
|
+
return command[0]; // Return the command id
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BotState,
|
|
3
|
+
ConversationState,
|
|
4
|
+
MemoryStorage,
|
|
5
|
+
SigninStateVerificationQuery,
|
|
6
|
+
StatePropertyAccessor,
|
|
7
|
+
TeamsActivityHandler,
|
|
8
|
+
TurnContext,
|
|
9
|
+
UserState,
|
|
10
|
+
} from "botbuilder";
|
|
11
|
+
import { showUserInfo } from "./showUserInfo";
|
|
12
|
+
import { SsoDialog } from "./ssoDialog";
|
|
13
|
+
|
|
14
|
+
export class TeamsSsoBot extends TeamsActivityHandler {
|
|
15
|
+
private dialog: SsoDialog;
|
|
16
|
+
private userState: BotState;
|
|
17
|
+
private conversationState: BotState;
|
|
18
|
+
private dialogState: StatePropertyAccessor;
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
|
|
23
|
+
// Define the state store for your bot.
|
|
24
|
+
// See https://aka.ms/about-bot-state to learn more about using MemoryStorage.
|
|
25
|
+
// A bot requires a state storage system to persist the dialog and user state between messages.
|
|
26
|
+
const memoryStorage = new MemoryStorage();
|
|
27
|
+
|
|
28
|
+
// Create conversation and user state with in-memory storage provider.
|
|
29
|
+
this.conversationState = new ConversationState(memoryStorage);
|
|
30
|
+
this.userState = new UserState(memoryStorage);
|
|
31
|
+
this.dialog = new SsoDialog(new MemoryStorage(), ["User.Read"]);
|
|
32
|
+
this.dialogState = this.conversationState.createProperty("DialogState");
|
|
33
|
+
|
|
34
|
+
// Add commands that requires user authentication
|
|
35
|
+
this.dialog.addCommand("ShowUserProfile", "show", showUserInfo);
|
|
36
|
+
// call the `addCommand` function to add more customized commands
|
|
37
|
+
|
|
38
|
+
this.onMessage(async (context, next) => {
|
|
39
|
+
console.log("Running with Message Activity.");
|
|
40
|
+
|
|
41
|
+
// Run the Dialog with the new message Activity.
|
|
42
|
+
await this.dialog.run(context, this.dialogState);
|
|
43
|
+
|
|
44
|
+
// By calling next() you ensure that the next BotHandler is run.
|
|
45
|
+
await next();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async run(context: TurnContext) {
|
|
50
|
+
await super.run(context);
|
|
51
|
+
|
|
52
|
+
// Save any state changes. The load happened during the execution of the Dialog.
|
|
53
|
+
await this.conversationState.saveChanges(context, false);
|
|
54
|
+
await this.userState.saveChanges(context, false);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async handleTeamsSigninVerifyState(context: TurnContext, query: SigninStateVerificationQuery) {
|
|
58
|
+
console.log("Running dialog with signin/verifystate from an Invoke Activity.");
|
|
59
|
+
await this.dialog.run(context, this.dialogState);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async handleTeamsSigninTokenExchange(context: TurnContext, query: SigninStateVerificationQuery) {
|
|
63
|
+
await this.dialog.run(context, this.dialogState);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async onSignInInvoke(context: TurnContext) {
|
|
67
|
+
await this.dialog.run(context, this.dialogState);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
## How to enable SSO in TeamsFx Tab projects
|
|
2
|
+
|
|
3
|
+
This doc will show you how to add Single Sign On feature to TeamsFx Tab projects. Note that this article is only for Teams Toolkit Visual Studio Code Extension version after x.x.x or TeamsFx CLI version after x.x.x.
|
|
4
|
+
|
|
5
|
+
*Note: This article is only for TeamsFx projects by Javascript and Typescript. For Dotnet, please refer to ${help link}.*
|
|
6
|
+
|
|
7
|
+
### Step 1: Enable Single Sign On with TeamsFx commands
|
|
8
|
+
|
|
9
|
+
You can follow the following steps to add SSO feature to your TeamsFx projects.
|
|
10
|
+
- From Visual Studio Code: open the command palette and select: `Teams: Add SSO`.
|
|
11
|
+
- From TeamsFx CLI: run command `teamsfx add sso` in your project directory.
|
|
12
|
+
|
|
13
|
+
What TeamsFx will do when trigger this command:
|
|
14
|
+
|
|
15
|
+
1. Create Azure AD app template under `template\appPackage\aad.template.json`
|
|
16
|
+
|
|
17
|
+
1. Add `webApplicationInfo` object in Teams App manifest
|
|
18
|
+
|
|
19
|
+
1. Create `README.md` and sample code under `auth/tab/`
|
|
20
|
+
|
|
21
|
+
### Step 2: Update your source code
|
|
22
|
+
|
|
23
|
+
There are two folders under `auth/tab`: `public` and `sso`.
|
|
24
|
+
|
|
25
|
+
1. In `public`, there are two html files which is used for authentication. You can simply copy the files under the folder and place it under `tabs/public/`.
|
|
26
|
+
|
|
27
|
+
2. In `sso`, there is one file. You can simply copy the folder and place it under `tabs/src/sso/`.
|
|
28
|
+
- `GetUserProfile`: This file implement a function that calls Microsoft Graph API to get user info.
|
|
29
|
+
- You need to manually run the following commands under `tabs/`:
|
|
30
|
+
```
|
|
31
|
+
npm install @microsoft/teamsfx-react
|
|
32
|
+
```
|
|
33
|
+
- You need to manually add the following lines to `tabs/src/components/sample/Welcome.tsx` to import `GetUserProfile`:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
import { GetUserProfile } from "../sso/GetUserProfile";
|
|
37
|
+
```
|
|
38
|
+
and replace the following line:
|
|
39
|
+
```
|
|
40
|
+
<AddSSO />
|
|
41
|
+
```
|
|
42
|
+
with:
|
|
43
|
+
```
|
|
44
|
+
<GetUserProfile />
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Step 3: Provision Azure AD app and deploy latest code
|
|
48
|
+
|
|
49
|
+
After running `add sso` command and updating source code, you need to run `Provision` + `Deploy` or `Local Debug` again to provision an Azure AD app for Single Sign On. After the above steps, Single Sign On is successfully added in your Teams App.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<!--This file is added by us when enable SSO. Developers can use it directly, or reference this sample to create their own auth end page.-->
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<!--This file is used during the Teams authentication flow to assist with retrieval of the access token.-->
|
|
5
|
+
<!--If you're not familiar with this, do not alter or remove this file from your project.-->
|
|
6
|
+
<html>
|
|
7
|
+
<head>
|
|
8
|
+
<title>Login End Page</title>
|
|
9
|
+
<meta charset="utf-8" />
|
|
10
|
+
</head>
|
|
11
|
+
|
|
12
|
+
<body>
|
|
13
|
+
<script
|
|
14
|
+
src="https://statics.teams.cdn.office.net/sdk/v1.6.0/js/MicrosoftTeams.min.js"
|
|
15
|
+
integrity="sha384-mhp2E+BLMiZLe7rDIzj19WjgXJeI32NkPvrvvZBrMi5IvWup/1NUfS5xuYN5S3VT"
|
|
16
|
+
crossorigin="anonymous"
|
|
17
|
+
></script>
|
|
18
|
+
<script
|
|
19
|
+
type="text/javascript"
|
|
20
|
+
src="https://alcdn.msauth.net/browser/2.21.0/js/msal-browser.min.js"
|
|
21
|
+
integrity="sha384-s/NxjjAgw1QgpDhOlVjTceLl4axrp5nqpUbCPOEQy1PqbFit9On6uw2XmEF1eq0s"
|
|
22
|
+
crossorigin="anonymous">
|
|
23
|
+
</script>
|
|
24
|
+
<script type="text/javascript">
|
|
25
|
+
var currentURL = new URL(window.location);
|
|
26
|
+
var clientId = currentURL.searchParams.get("clientId");
|
|
27
|
+
|
|
28
|
+
microsoftTeams.initialize();
|
|
29
|
+
microsoftTeams.getContext(async function (context) {
|
|
30
|
+
const msalConfig = {
|
|
31
|
+
auth: {
|
|
32
|
+
clientId: clientId,
|
|
33
|
+
authority: `https://login.microsoftonline.com/${context.tid}`,
|
|
34
|
+
navigateToLoginRequestUrl: false
|
|
35
|
+
},
|
|
36
|
+
cache: {
|
|
37
|
+
cacheLocation: "sessionStorage",
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const msalInstance = new window.msal.PublicClientApplication(msalConfig);
|
|
42
|
+
msalInstance.handleRedirectPromise()
|
|
43
|
+
.then((tokenResponse) => {
|
|
44
|
+
if (tokenResponse !== null) {
|
|
45
|
+
microsoftTeams.authentication.notifySuccess(JSON.stringify({
|
|
46
|
+
sessionStorage: sessionStorage
|
|
47
|
+
}));
|
|
48
|
+
} else {
|
|
49
|
+
microsoftTeams.authentication.notifyFailure("Get empty response.");
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.catch((error) => {
|
|
53
|
+
microsoftTeams.authentication.notifyFailure(error);
|
|
54
|
+
});
|
|
55
|
+
})
|
|
56
|
+
</script>
|
|
57
|
+
</body>
|
|
58
|
+
</html>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<!--This file is added by us when enable SSO. Developers can use it directly, or reference this sample to create their own auth end page.-->
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<!--This file is used during the Teams authentication flow to assist with retrieval of the access token.-->
|
|
5
|
+
<!--If you're not familiar with this, do not alter or remove this file from your project.-->
|
|
6
|
+
<html>
|
|
7
|
+
<head>
|
|
8
|
+
<title>Login Start Page</title>
|
|
9
|
+
<meta charset="utf-8" />
|
|
10
|
+
</head>
|
|
11
|
+
|
|
12
|
+
<body>
|
|
13
|
+
<script
|
|
14
|
+
src="https://statics.teams.cdn.office.net/sdk/v1.6.0/js/MicrosoftTeams.min.js"
|
|
15
|
+
integrity="sha384-mhp2E+BLMiZLe7rDIzj19WjgXJeI32NkPvrvvZBrMi5IvWup/1NUfS5xuYN5S3VT"
|
|
16
|
+
crossorigin="anonymous"
|
|
17
|
+
></script>
|
|
18
|
+
<script
|
|
19
|
+
type="text/javascript"
|
|
20
|
+
src="https://alcdn.msauth.net/browser/2.21.0/js/msal-browser.min.js"
|
|
21
|
+
integrity="sha384-s/NxjjAgw1QgpDhOlVjTceLl4axrp5nqpUbCPOEQy1PqbFit9On6uw2XmEF1eq0s"
|
|
22
|
+
crossorigin="anonymous">
|
|
23
|
+
</script>
|
|
24
|
+
<script type="text/javascript">
|
|
25
|
+
microsoftTeams.initialize();
|
|
26
|
+
|
|
27
|
+
// Get the tab context, and use the information to navigate to Azure AD login page
|
|
28
|
+
microsoftTeams.getContext(async function (context) {
|
|
29
|
+
// Generate random state string and store it, so we can verify it in the callback
|
|
30
|
+
var currentURL = new URL(window.location);
|
|
31
|
+
var clientId = currentURL.searchParams.get("clientId");
|
|
32
|
+
var scope = currentURL.searchParams.get("scope");
|
|
33
|
+
var loginHint = currentURL.searchParams.get("loginHint");
|
|
34
|
+
|
|
35
|
+
const msalConfig = {
|
|
36
|
+
auth: {
|
|
37
|
+
clientId: clientId,
|
|
38
|
+
authority: `https://login.microsoftonline.com/${context.tid}`,
|
|
39
|
+
navigateToLoginRequestUrl: false
|
|
40
|
+
},
|
|
41
|
+
cache: {
|
|
42
|
+
cacheLocation: "sessionStorage",
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const msalInstance = new msal.PublicClientApplication(msalConfig);
|
|
47
|
+
const scopesArray = scope.split(" ");
|
|
48
|
+
const scopesRequest = {
|
|
49
|
+
scopes: scopesArray,
|
|
50
|
+
redirectUri: window.location.origin + `/auth-end.html?clientId=${clientId}`,
|
|
51
|
+
loginHint: loginHint
|
|
52
|
+
};
|
|
53
|
+
await msalInstance.loginRedirect(scopesRequest);
|
|
54
|
+
});
|
|
55
|
+
</script>
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Button } from "@fluentui/react-northstar";
|
|
2
|
+
import { useGraph, useTeamsFx } from "@microsoft/teamsfx-react";
|
|
3
|
+
|
|
4
|
+
export function GetUserProfile() {
|
|
5
|
+
const { teamsfx } = useTeamsFx();
|
|
6
|
+
const { loading, error, data, reload } = useGraph(
|
|
7
|
+
async (graph, teamsfx, scope) => {
|
|
8
|
+
// Call graph api directly to get user profile information
|
|
9
|
+
const profile = await graph.api("/me").get();
|
|
10
|
+
|
|
11
|
+
let photoUrl = "";
|
|
12
|
+
try {
|
|
13
|
+
const photo = await graph.api("/me/photo/$value").get();
|
|
14
|
+
photoUrl = URL.createObjectURL(photo);
|
|
15
|
+
} catch {
|
|
16
|
+
// Could not fetch photo from user's profile, return empty string as placeholder.
|
|
17
|
+
}
|
|
18
|
+
return { profile, photoUrl };
|
|
19
|
+
},
|
|
20
|
+
{ scope: ["User.Read"], teamsfx: teamsfx }
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div>
|
|
25
|
+
<h2>GetUserProfile</h2>
|
|
26
|
+
<p>Click below to authorize button to grant permission to using Microsoft Graph.</p>
|
|
27
|
+
<Button primary content="Authorize" disabled={loading} onClick={reload} />
|
|
28
|
+
{!loading && error && (
|
|
29
|
+
<div className="error">Failed to read your profile. Please try again later.</div>
|
|
30
|
+
)}
|
|
31
|
+
{!loading && data && <div>Hello {data.profile.displayName}</div>}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|