azure – 如何从控制台应用程序调用Microsoft Graph c#
我需要调用Microsoft Graph API在Azure AD中创建用户.
首先,我需要从控制台应用程序进行测试,然后需要在Azure功能中实现. https://developer.microsoft.com/en-us/graph/graph-explorer 我是Microsoft Graph API的新手,如何从c#console应用程序连接和执行API. 我已经在AAD注册了该应用程序. 我正在尝试获取令牌: string resourceId = "https://graph.microsoft.com"; string tenantId = "<tenantID>"; string authString = "https://login.microsoftonline.com/" + tenantId; string upn = String.Empty; string clientId = "<ClientID>"; string clientSecret = "<clientSecret>"; //string clientSecret = ConfigurationManager.AppSettings["clientSecret"]; log.Verbose("ClientSecret=" + clientSecret); log.Verbose("authString=" + authString); var authenticationContext = new AuthenticationContext(authString,false); // Config for OAuth client credentials ClientCredential clientCred = new ClientCredential(clientId,clientSecret); AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resourceId,clientCred); string token = authenticationResult.AccessToken; log.Verbose("token=" + token); 我试图使用现有的AADB2C. 我已启用权限: 我既没有得到异常也没有得到访问令牌和程序默默退出 另外: 有新的图书馆 <package id="Microsoft.Identity.Client" version="1.1.0-preview" targetFramework="net46" /> 如何在没有登录弹出的情况下使用以下命令直接登录并获取令牌? 解决方法
要从控制台应用程序进行连接,您需要先获取有效令牌.由于您缺少UI,因此您需要
Get access without a user.请注意,此类“仅限应用”令牌需要使用
Administrative Consent才能使用.
为了支持Create User方案,您需要确保permission scopes包含User.ReadWrite.All. 获得有效令牌后,您可以调用Graph API. Graph是一个REST API,因此所有调用都是通过HTTP在Authorization Header中传递的令牌进行的. 您可以在Get started with Microsoft Graph and REST阅读一般概述.还有一些语言/框架特定的概述可用,但所有这些概述都假设您有一个UI(即不仅仅是控制台).一般来说,如果您正在寻找用于创建用户的控制台工具,您可能更喜欢使用PowerShell. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- windows-server-2008 – Vertex 2 SSD一次冻结60秒
- 带Rcpp和CMake的R包(Windows)
- windows-store-apps – 在Windows应用商店或通用应用中注册
- windows – 好/免费工具或备份驱动程序的方法
- cx_freeze include_msvcr没有捆绑Windows VC2015运行时
- windows-server-2003 – Windows任务调度程序电子邮件通知?
- 如何快速测试Windows小工具?
- 如何隐藏桌面的特定捷径
- windows-server-2008 – 用于远程桌面登录失败的Windows事件
- 学习Windows应用商店xaml的最佳资源?