如果尚未添加登录用户,如何使用C#将新用户添加到Azure Active Directory? [英] How to add a new user to Azure Active Directory using C# if the logging in user is not added already?

查看:90
本文介绍了如果尚未添加登录用户,如何使用C#将新用户添加到Azure Active Directory?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Azure Active Directory实现单点登录,并且我已经实现了它并且如果已经在目录中添加了用户,则工作正常。现在我想检查用户是否已经添加,如果不需要通过c#代码添加(如果用户
id属于特定域)并允许登录。我已经做了一些R& D并且来到知道我们可以使用Graph API来做到这一点。但不知道在哪里或如何开始。任何帮助将不胜感激。

I am trying to implement single sign on using Azure Active Directory and I have implemented it and working fine if user is already added in the directory. Now I want to check whether a user is already added and if not need to add through c# code(if the user id is of a particular domain) and allow log in. I have done some R&D and came to know that we can do that using Graph API. But don't know where or how to start. Any help will be appreciated.

提前致谢。

Jai

推荐答案

您好,

首先我们无法知道是否存在问题或没有代码存在问题。 

First off we can't know if there is a problem or what the problem is without code. 

注意:以下所示的所有代码都无法在其创建的解决方案之外运行,而是一种可以遵循的地图。

NOTE: All the code shown below will not work outside of the solution it was created in but instead is kind of a map to follow.

你应该使用Graph API作为此处指示
,它提供基本REST调用以确定用户是否存在。使用类执行此操作的旧方法已过时,不应使用。

You should be using the Graph API as indicated here which gives the base REST call to determine if a user exists. The old way of doing this with classes is obsolete and should not be used.

我没有代码示例,因为我们将方法分解为逻辑部分。我可以说你应该编写单元测试来添加/检查你的内容。

I don't have a code sample as we have our methods broken up into logical parts. What I can say is you should write unit test to add/check what you are after.

这是我们用于测试添加,存在的同一主题的两个单元测试和删除。 groupObjectId和userObjectId的值来自Azure在线管理页面。

Here is two of our unit test that are the same topic we use to test for adding, existence and removal. The values for groupObjectId and userObjectId come from Azure online admin pages.

/// <summary>
/// Add an existing user to an existing group
/// </summary>
[TestTraits(Trait.AzureGraphApi)]
[TestMethod]
public void AddUserToGroup()
{
    var operations = new AzureGraphRestClient(new HttpClient());
    var groupObjectId = "57f7eccb-222a-4969-9te4-cfb743ba4368";
    var userObjectId = "6094c94a-cdfb-47c5-90b4-a302672de4be";

    if (operations.IsGroupMember(


" groups / {groupObjectId} /
"groups/{groupObjectId}/


links / members?" ,userObjectId))
{
var result = operations.RemoveUserToGroup(
links/members?", userObjectId)) { var result = operations.RemoveUserToGroup(


这篇关于如果尚未添加登录用户,如何使用C#将新用户添加到Azure Active Directory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆