小编sid*_*hah的帖子

如何从 Microsoft Graph API C# 中的电子邮件地址获取用户 ID

我想将用户添加到组中,但我没有用户的id,我只有电子邮件地址。

这是代码:

User userToAdd = await graphClient
    .Users["objectID"]
    .Request()
    .GetAsync();

await graphClient
    .Groups["groupObjectID"]
    .Members
    .References
    .Request()
    .AddAsync(userToAdd);
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我如何使用 Microsoft Graph 从电子邮件地址检索 ObjectId(用户 ID)?

c# microsoft-graph-api

8
推荐指数
3
解决办法
2万
查看次数

AADSTS70011:输入参数“ scope”提供的值无效

因此,我有一个方案,在该方案中,应在特定条件下将用户添加到组中。此外,当应用程序开始运行时,也不应要求用户登录其Microsoft ID / PWD。因此,我访问创建了Graph Service Client对象的令牌,如下所示:

GraphServiceClient graphClient = new GraphServiceClient(
    "https://graph.microsoft.com/v1.0", 
    new DelegateAuthenticationProvider(
        async (requestMessage) =>
        {
            string clientId = "My APP ID";
            string authorityFormat = "https://login.microsoftonline.com/{0}/v2.0";
            string tenantId = "tenant GUID";
            string[] _scopes = new string[] { 
                "https://graph.microsoft.com/User.ReadBasic.All" 
            };
            // Custom Redirect URI asigned in the Application Registration 
            // Portal in the native Application Platform
            string redirectUri = "https://localhost:4803/"; 
            string clientSecret = "App Secret";
            ConfidentialClientApplication daemonClient = new ConfidentialClientApplication(
                clientId, 
                String.Format(authorityFormat, tenantId), 
                redirectUri, 
                new ClientCredential(clientSecret), 
                null, new TokenCache() …
Run Code Online (Sandbox Code Playgroud)

c# microsoft-graph

6
推荐指数
1
解决办法
4722
查看次数

标签 统计

c# ×2

microsoft-graph ×1

microsoft-graph-api ×1