问题描述
我试图在Azure AD中创建用户,而没有成功创建mail
字段.创建用户时,我需要在Azure AD中添加电子邮件ID.
I was trying to create a user in Azure AD without mail
filed is user created successfully. I need to add the email id in Azure AD at the time of user created.
我在json中添加了mail
属性,它显示为
I added the mail
property in json and it says
我的C#代码是:
var url = string.Format("https://graph.windows.net/{0}/users?api-version=1.6",oauthsettings.TenantId);
var authDetails = _orchardServices.WorkContext.CurrentSite.As<AzureAuthenticationPart>();
var alogin = new AzureLogin();
var jwttoken = alogin.ServiceAuth(authDetails.ClientId, authDetails.ClientSecret);
var aadUser =new {
mail=email,
accountEnabled = true,
displayName = userName,
mailNickname = userName,
passwordProfile = new passwordProfile()
{
password = password,
forceChangePasswordNextLogin = authDetails.IsUpdatePwdNextLogin
},
userPrincipalName = userName + oauthsettings.DirectoryName,
};
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + jwttoken);
var modelval = Convert.ToString(JsonConvert.SerializeObject(aadUser));
var content = new StringContent(modelval, Encoding.UTF8, "application/json");
var result = client.PostAsync(url, content).Result;
登录后从Azure AD获取访问令牌
Get Access Token from Azure AD After Login
JwtSecurityToken token = GetAccessToken(authDetails, code, returnUrl);
var claims = token.Claims;
return LogOn(claims, returnUrl);
从JWT获取电子邮件
public LogOnResponse LogOn(IEnumerable<System.Security.Claims.Claim> claims, string returnUrl)
{
var email = claims.FirstOrDefault(s => s.Type == "email").Value;
在这个地方,我无法获得访问令牌,因为用户创建的时间未在Graph API Request中设置电子邮件.我还有一个问题是,该电子邮件ID仅基于我也验证了另一个站点,因此我需要在用户创建的时间内设置电子邮件.
In this place I can't get the access token, because the user created time is not set the email in Graph API Request. I have another problem is this email id based only I was validate another site also, so I was required set the email in user created time.
我需要电子邮件ID才能登录我的应用程序.我将Azure AD集成到了电子邮件所需的现有应用程序中.
I required email id for login in my application. i was integrate the Azure AD in existing application it's required for email.
有人知道如何在用户的Azure AD中设置电子邮件ID.
Does anyone know how to set the email id in Azure AD for a user.
我在邮递员中的要求.对请求中添加的电子邮件的响应
My Request in Postman. Response for Email Added in Request
推荐答案
由于mail属性绑定到Exchange Online,因此除非您拥有Exchange Online许可证,否则我们不允许您写入该属性.当您为用户激活许可证时,Exchange Online将在创建用户邮箱的过程中使用正确的邮箱邮件地址更新该字段.您可以在创建用户期间使用"MailNickName"和其他电子邮件".此字段还将取决于它是本地帐户(B2C)"还是工作或学校帐户".
Because the mail attribute is tied to Exchange Online, we don't permit you to write to that attribute unless you have an Exchange Online license. When you activate a license for the user, Exchange Online will update the field with the correct mailbox mail address during the creation of the user's mailbox. You can utilize "MailNickName" and " other emails" during the creation of a user. This field will also depend upon if it is a "local account (B2C)" or "work or school account".
我希望这能回答您有关邮件"属性为只读"的问题
I hope this answers your question concerning the "mail" attribute being "read-only"
这篇关于Azure AD:属性"mail"为只读,无法设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!