[英]Azure Active Directory Users (type=User with an existing user account) Json to List Model is giving null
I want to deserialize Json result into a model. 我想将Json结果反序列化为模型。 I am using Azure Single sign on method.
我正在使用Azure单一登录方法。 when I am login with new new created user in ad (new user in your organization) i am getting proper user info.
当我用广告中新创建的新用户(您单位中的新用户)登录时,我得到了正确的用户信息。 but if i created new user in AzureAd with "User with an existing user account".I am able to log in and request is also authenticated.
但是,如果我使用“使用现有用户帐户的用户”在AzureAd中创建了新用户。我可以登录并验证请求。 but i am not getting user profile.
但是我没有用户资料。 user profile is null.
用户个人资料为空。 but "responseString" contains all values for user.
但是“ responseString”包含用户的所有值。 can any one help me for that ?
有人可以帮我吗?
UserProfile profile = JsonConvert.DeserializeObject<UserProfile>(responseString);
public class UserProfile
{
public string DisplayName { get; set; }
public string GivenName { get; set; }
public string Surname { get; set; }
}
Json JSON
User with an existing user account 具有现有用户帐户的用户
{"odata.metadata":"https://graph.windows.net/780cdd84-48ba-4be3-8d66-b40b8bee6b0b/$metadata#directoryObjects/Microsoft.WindowsAzure.ActiveDirectory.User","value":[{"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User","objectType":"User","objectId":"****************","accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"mahesh","facsimileTelephoneNumber":null,"givenName":"map","jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"devb_azureteam.com#EXT#","mobile":null,"otherMails":["devb@azureteam.com"],"passwordPolicies":"None","passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":null,"provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"state":null,"streetAddress":null,"surname":"map","telephoneNumber":null,"usageLocation":null,"userPrincipalName":"devb_azureteam.com#EXT#@AzureteamLoginTest.onmicrosoft.com"},
{"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User","objectType":"User","objectId":"****************","accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"Education at AzureTeam","facsimileTelephoneNumber":null,"givenName":"Education","jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"education_azureteam.com#EXT#","mobile":null,"otherMails":["education@azureteam.com"],"passwordPolicies":null,"passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":null,"provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"state":null,"streetAddress":null,"surname":"at AzureTeam","telephoneNumber":null,"usageLocation":null,"userPrincipalName":"education_azureteam.com#EXT#@AzureteamLoginTest.onmicrosoft.com"},
{"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User","objectType":"User","objectId":"*****************","accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"mahesh","facsimileTelephoneNumber":null,"givenName":"mahesh","jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"mahesh","mobile":null,"otherMails":["map@azureteam.com"],"passwordPolicies":"None","passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":null,"provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"state":null,"streetAddress":null,"surname":null,"telephoneNumber":null,"usageLocation":null,"userPrincipalName":"mahesh@AzureteamLoginTest.onmicrosoft.com"}]}
New user in organization
{"odata.metadata":"https://graph.windows.net/780cdd84-48ba-4be3-8d66-b40b8bee6b0b/$metadata#directoryObjects/Microsoft.WindowsAzure.ActiveDirectory.User/@Element","odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User","objectType":"User","objectId":"************","accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"mahesh","facsimileTelephoneNumber":null,"givenName":"mahesh","jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"mahesh","mobile":null,"otherMails":["map@azureteam.com"],"passwordPolicies":"None","passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":null,"provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"state":null,"streetAddress":null,"surname":null,"telephoneNumber":null,"usageLocation":null,"userPrincipalName":"mahesh@AzureteamLoginTest.onmicrosoft.com"}
You actually get different JSON's. 您实际上得到了不同的JSON。 I simplified them to show the problem.
我简化了它们以显示问题。 For new user JSON looks like that:
对于新用户,JSON如下所示:
{
"odata.metadata":"...Microsoft.WindowsAzure.ActiveDirectory.User/@Element",
"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User",
"displayName":"mahesh",
"givenName":"mahesh",
"surname":null
}
Deserialization will work with your model. 反序列化将与您的模型一起使用。 But for existing user JSON is:
但是对于现有用户,JSON是:
{
"odata.metadata":"...Microsoft.WindowsAzure.ActiveDirectory.User",
"value":[
{
"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User",
"displayName":"mahesh",
"givenName":"map",
"surname":"map"
},
{ },
{ }
]
}
As you can see you have a value
property that holds an array of users. 如您所见,您具有一个
value
属性,该属性包含一个用户数组。 So to be able to deserialize it you will need to create new model: 因此,要进行反序列化,您将需要创建新模型:
public class RootObject
{
public List<UserProfile> Value { get; set; }
}
And then: 接着:
var obj = JsonConvert.DeserializeObject<RootObject>(json);
I'm not similar with Azure Active Directory but you should check why odata.metadata
property is different for these responses. 我与Azure Active Directory不同,但是您应该检查为什么这些响应的
odata.metadata
属性不同。
I got the saluting :) 我得到了敬礼:)
Add this block in your global.asax 在您的global.asax中添加此块
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
ClaimsIdentity id = ((ClaimsIdentity)User.Identity);
Claim claim = id.FindFirst(ClaimTypes.Email);
if (claim != null)
{
string email = claim.Value;
id.AddClaim(new Claim(ClaimTypes.Name, email));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.