我正在尝试从 Microsoft 团队获取 AuthToken,尽管按照书本进行了所有操作,但我得到了一个错误。我知道关于 SO 有一个类似的问题,但我尝试了每一个建议,仍然没有奏效。这是我的标签代码:
useEffect(() => {
if (inTeams === true) {
microsoftTeams.authentication.getAuthToken({
successCallback: (result) => {
console.log(result)
},
failureCallback: function (error) {
console.log(error)
}
});
} else {
setEntityId("Not in Microsoft Teams");
}
}, [inTeams]);
这是我的manifest.json.
文件,我不确定“webApplicationInfo”部分是否在正确的位置:
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.11/MicrosoftTeams.schema.json",
"manifestVersion": "1.11",
"id": "{{APPLICATION_ID}}",
"version": "{{VERSION}}",
"packageName": "{{PACKAGE_NAME}}",
"developer": {
"name": "Vizibit",
"websiteUrl": "https://{{PUBLIC_HOSTNAME}}",
"privacyUrl": "https://{{PUBLIC_HOSTNAME}}/privacy.html",
"termsOfUseUrl": "https://{{PUBLIC_HOSTNAME}}/tou.html"
},
"name": {
"short": "TeamsAddIn",
"full": "TeamsAddIn"
},
"description": {
"short": "TODO: add short description here",
"full": "TODO: add full description here"
},
"icons": {
"outline": "icon-outline.png",
"color": "icon-color.png"
},
"accentColor": "#D85028",
"configurableTabs": [
{
"configurationUrl": "https://{{PUBLIC_HOSTNAME}}/signatorDemoTab/config.html?name={loginHint}&tenant={tid}&group={groupId}&theme={theme}",
"canUpdateConfiguration": true,
"scopes": [
"team"
]
}
],
"staticTabs": [],
"bots": [],
"connectors": [],
"composeExtensions": [],
"permissions": [
"identity",
"messageTeamMembers"
],
"validDomains": [
"{{PUBLIC_HOSTNAME}}"
],
"showLoadingIndicator": true,
"webApplicationInfo": {
"id": "{{APPLICATION_ID}}",
"resource": "api://{{PUBLIC_HOSTNAME}}/{{APPLICATION_ID}}"
}
}
我得到的错误:
这也在错误中:
谢谢 :)
更新:
这就是我使用的:
useEffect(() => {
if (inTeams === true) {
microsoftTeams.authentication.getAuthToken({
successCallback: (result) => {
const serviceRequest: AuthRequest = {
client_id: "[CLIENTID]",
client_secret: "[CLIENTSECRET]",
requested_token_use: "on_behalf_of",
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
scope:
"api://[MYNGROK].ngrok.io/[CLIENTID]",
assertion: result,
};
httpClient.GetAuthenticationToken(serviceRequest).then((res) => {
console.log(res);
});
microsoftTeams.appInitialization.notifySuccess();
},
failureCallback: function (error) {
console.log(error);
},
});
} else {
setEntityId("Not in Microsoft Teams");
}
}, [inTeams]);
"error_description": "AADSTS7000215: Invalid client secret provided. Ensure the secret being sent in the request is the client secret value, not the client secret ID, for a secret added to app '[CLIENTID]'.\r\nTrace ID: 2dc1bddf-a15c-45a8-9346-4d2b83011600\r\nCorrelation ID: cf790d06-19e5-49c4-a79c-364f044d7ee8\r\nTimestamp: 2022-03-31 11:39:59Z",
我的客户密码是正确的,我不知道为什么会出现这个错误。
更新:仍然得到相同的 CORS 错误,即使我设法在邮递员中解决它,仍然无法在 React axios 中解决。
var formData = new URLSearchParams();
formData.append("client_id", "[CLIENT_ID]");
formData.append(
"client_secret",
"[CLIENT_SECRET]"
);
formData.append("requested_token_use", "on_behalf_of");
formData.append(
"grant_type",
"urn:ietf:params:oauth:grant-type:jwt-bearer"
);
formData.append(
"scope",
"api://[NGROK].ngrok.io/[CLIENT_ID]/scope"
);
formData.append("assertion", result);
axios.post("https://login.microsoftonline.com/common/oauth2/v2.0/token", formData);
我不知道您正在做哪些文档(即您是“通过”哪本书),因为其中一些(许多)非常古老,需要完全重写。最好的来源是这个:https ://docs.microsoft.com/en-us/microsoftteams/platform/tabs/how-to/authentication/auth-aad-sso?tabs=dotnet
这是一个很棒的视频概述:https ://www.youtube.com/watch?v= kruUnaZgQaY 这是一个示例(涵盖节点和 dotnet):https ://github.com/pnp/teams-dev-samples/tree /main/samples/tab-sso
也就是说,您发布的底部屏幕截图中似乎显示了错误 - 您需要获得该应用程序的管理员同意。在此处查看更多信息:https ://docs.microsoft.com/en-us/microsoftteams/platform/tabs/how-to/authentication/auth-aad-sso?tabs=dotnet#tenant-admin-consent
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句