用于 JavaScript 的 Azure GraphRbac 管理客户端 SDK
3⁄4 ̄ ̧漯B: 此软件包用于与 Azure Active 目录图 API 合作,该图已贬值并被替换为 微软图形 API. 从2022年6月30日起,使用 Azure AD Graph 的应用程序将不再收到 Azure Active Directory Graph 端点的回复.
帮助链接 :
- 更新您的应用程序以使用 Microsoft 认证库和 Microsoft Graph API
- 应用程序迁移核对表
- @ microsoft/ microsoft-graph-客户端包 用于更新的微软图形 API
目前得到支持的环境
- 节点.js 6.x.x 或更高版本
- 浏览器 JavaScript
如何安装
npm install @azure/graph
如何使用
nodejs - 认证,客户端创建并获得签名的InUser,作为TypeScript所写的示例.
安装 @ azure/ ms- rest- nodeaut
npm install @azure/ms-rest-nodeauth
样本代码
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
import {
GraphRbacManagementClient,
GraphRbacManagementModels,
GraphRbacManagementMappers
} from "@azure/graph";
const tenantId = "<Tenant_Id>";
msRestNodeAuth
.interactiveLogin({
tokenAudience: "https://graph.windows.net",
domain: tenantId
})
.then((creds) => {
const client = new GraphRbacManagementClient(creds, tenantId, {
baseUri: "https://graph.windows.net"
});
client.signedInUser.get().then((result) => {
console.log("The result is:");
console.log(result);
});
})
.catch((err) => {
console.error(err);
});
浏览器 - 认证,客户端创建并获得签名的InUser作为JavaScript所写的示例.
安装 @azure/ ms- rest- browseauth
npm install @azure/ms-rest-browserauth
样本代码
见 https://github.com/Azure/ms-rest-browserauth 页面存档备份,存于互联网档案馆 在浏览器中学习如何认证给Azure.
- 索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/graph sample</title>
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
<script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script>
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
<script src="node_modules/@azure/graph/dist/graph.js"></script>
<script type="text/javascript">
const tenantId = "<Tenant_Id>";
const authManager = new msAuth.AuthManager({
clientId: "<client id for your Azure AD app>",
tenant: "<optional tenant for your organization>"
});
authManager.finalizeLogin().then((res) => {
if (!res.isLoggedIn) {
// may cause redirects
authManager.login();
}
const client = new Azure.Graph.GraphRbacManagementClient(res.creds, tenantId, {
baseUri: "https://graph.windows.net"
});
client.signedInUser
.get()
.then((result) => {
console.log("The result is:");
console.log(result);
})
.catch((err) => {
console.log("An error occurred:");
console.error(err);
});
});
</script>
</head>
<body></body>
</html>
相关项目
