Manage your Azure AD users - download from Nuget Package.
- Intialiaze the Graph Client
var graphClient = new GraphClient("clientId",
"clientSecret",
"tenant");
- GET all users on azure active directory
var users = graphClient.GetAllUsers().Result.ToString();
List<User> usersLi = JsonConvert.DeserializeObject<List<User>>(users.ToString());
- GET user by email
var userResult = graphClient.GetAllUsers("achraf123@gridnex.co").Result.ToString();
List<User> user = JsonConvert.DeserializeObject<List<User>>(userResult.ToString());
- Disable user
var Disablereslt = graphClient.DisableUser(user.First().objectId).Result;
- Enable user
var enablereslt = graphClient.EnableUser(user.First().objectId).Result;
- Check if user exist
var exist = graphClient.Exist(c.userPrincipalName).Result;
- Create new user
var user = new User()
{
accountEnabled = true,
displayName = "displayName",
mailNickname = "mailNickname",
passwordProfile = new Passwordprofile()
{
forceChangePasswordNextLogin = false,
password = "password"
},
userPrincipalName = "john.doe@domain.com"
};
var d = graphClient.CreateUser(c).Result;