Microsoft Azure> Azure Active Directory

时间:2018-07-16 14:33:48

标签: azure-ad-b2c

我创建了一个扩展名:

SchemaExtension objExtDef = new SchemaExtension()
{
    Description = "Extention to Store User Dates",
    Id = "UserDates",
    Properties = new List<ExtensionSchemaProperty>()
    {
        new ExtensionSchemaProperty() { Name = "CreateDate", Type = "DateTime" },
        new ExtensionSchemaProperty() { Name = "PasswordChangeDate", Type = "DateTime" }
    },
    TargetTypes = new List<string>()
    {
        "User"
    }
};


SchemaExtension schemaExtension = Task.Run(() => graphserviceClient.SchemaExtensions.Request().AddAsync(objExtDef)).Result;

使其可用:

var schemaExtension = new SchemaExtension
{
    Status = "Available",
};

var result = Task.Run(() => graphserviceClient.SchemaExtensions["extuce7u7qp_UserDates"].Request().UpdateAsync(schemaExtension)).Result;

搜索并确认它已创建并可用:

var lstAllExtensions = Task.Run(() => graphserviceClient.SchemaExtensions.Request().Filter("id%20eq%20'extuce7u7qp_UserDates'").GetAsync()).Result;

尝试在该扩展名中添加用户以及其他数据:

UserDatesExtension objUserDatesExtension = new UserDatesExtension();
objUserDatesExtension.CreateDate = DateTime.Today;
objUserDatesExtension.PasswordChangeDate = DateTime.Today;

dctExtensions.Add("extuce7u7qp_UserDates", objUserDatesExtension);

Microsoft.Graph.User objNewUser = new Microsoft.Graph.User
    {
        AccountEnabled = true,
        DisplayName = string.Format("{0} {1}", objUser.FirstName, objUser.LastName),
        MailNickname = "TestUC",
        PasswordProfile = new PasswordProfile
        {
            Password = "testpass",
            ForceChangePasswordNextSignIn = false
        },
        UserPrincipalName = string.Format("{0}@test.onmicrosoft.com", objUser.UserIdentity),
        GivenName = objUser.FirstName,
        Surname = objUser.LastName,
        City = objUser.Address != null ? objUser.Address.City : null,
        Country = objUser.Address != null ? objUser.Address.Country : null,
        State = objUser.Address != null ? objUser.Address.Region : null,
        MobilePhone = !string.IsNullOrEmpty(objUser.Phone) ? objUser.Phone : null,
        PreferredLanguage = objUser.PreferredLanguage,
        AdditionalData = dctExtensions
    };

    Microsoft.Graph.User objCreatedUser = Task.Run(() => graphserviceClient.Users.Request().AddAsync(objNewUser)).Result;

这引发了扩展ID无效的异常。

这是较早的工作。

UserDatesExtension类,在上面使用:

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
    public class UserDatesExtension
    {
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "CreateDate", Required = Newtonsoft.Json.Required.Default)]
        public DateTime CreateDate { get; set; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "PasswordChangeDate", Required = Newtonsoft.Json.Required.Default)]
        public DateTime PasswordChangeDate { get; set; }
    }

0 个答案:

没有答案