我想将用户添加到组中,但我没有用户的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)?
因此,我有一个方案,在该方案中,应在特定条件下将用户添加到组中。此外,当应用程序开始运行时,也不应要求用户登录其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)