带有外部帐户和 Microsoft Graph 的 Azure AD API
Azure AD with external accounts and Microsoft Graph API
我们正在将 Microsoft Azure Active Directory 设置为我们移动应用程序的 SSO 解决方案,但希望通过服务器端 Microsoft Graph 管理用户的帐户创建 API。
对于域的内部用户,这非常有效,因为我们使用 Graph API 作为管理员用户来创建帐户。
但是,在尝试创建外部帐户时(比如 joe.bloggs@gmail.com),这会失败。
我们正在使用 API 调用:
POST https://graph.microsoft.com/v1.0/users
BODY:
{
"accountEnabled": true,
"mailNickname": "joe.bloggs",
"displayName": "Joe Bloggs",
"givenName": "Joe",
"surname": "Bloggs",
"userPrincipalName": "joe.bloggs@gmail.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": false,
"password": "somepassword"
}
}
响应:
{
"error": {
"code": "Request_BadRequest",
"message": "Property userPrincipalName is invalid.",
"innerError": {
"request-id": "619450ec-e703-4a12-86e3-8f53c20d55fc",
"date": "2018-01-17T16:30:37"
},
"details": [
{
"target": "userPrincipalName",
"code": "InvalidValue"
}
]
}
}
说"userPrincipalName"无效,但是看了文档后我不确定API是否支持外部账户?
注意:我知道您可以使用“/beta/invitations”调用,但这不会创建帐户。
我假设你正在使用 Azure AD B2B 并希望将新的来宾用户添加到你的目录。
我想说明的一件事是,您可以邀请来宾用户加入您的目录,但您不能直接在您的目录中创建来宾用户。
因此,您可以使用 this Microsoft Graph API:
邀请来宾用户
请求
POST https://graph.microsoft.com/beta/invitations
Content-type: application/json
Content-length: 551
{
"invitedUserEmailAddress": "yyy@test.com",
"inviteRedirectUrl": "https://myapp.com"
}
回应
HTTP/1.1 201 OK
Content-type: application/json
Content-length: 551
{
"id": "7b92124c-9fa9-406f-8b8e-225df8376ba9",
"inviteRedeemUrl": "https://invitations.microsoft.com/redeem/?tenant=04dcc6ab-388a-4559-b527-fbec656300ea&user=7b92124c-9fa9-406f-8b8e-225df8376ba9&ticket=VV9dmiExBsfRIVNFjb9ITj9VXAd07Ypv4gTg%2f8PiuJs%3d&lc=1033&ver=2.0",
"invitedUserDisplayName": "yyy",
"invitedUserEmailAddress": "yyy@test.com",
"sendInvitationMessage": false,
"invitedUserMessageInfo": {
"messageLanguage": null,
"ccRecipients": [
{
"emailAddress": {
"name": null,
"address": null
}
}
],
"customizedMessageBody": null
},
"inviteRedirectUrl": "https://myapp.com/",
"status": "Completed",
"invitedUser": [ { "id": "243b1de4-ad9f-421c-a933-d55305fb165d" } ]
}
另外,如果您想在没有邀请的情况下邀请来宾用户,请参考this document。
希望对您有所帮助!
我们正在将 Microsoft Azure Active Directory 设置为我们移动应用程序的 SSO 解决方案,但希望通过服务器端 Microsoft Graph 管理用户的帐户创建 API。
对于域的内部用户,这非常有效,因为我们使用 Graph API 作为管理员用户来创建帐户。
但是,在尝试创建外部帐户时(比如 joe.bloggs@gmail.com),这会失败。
我们正在使用 API 调用:
POST https://graph.microsoft.com/v1.0/users
BODY:
{
"accountEnabled": true,
"mailNickname": "joe.bloggs",
"displayName": "Joe Bloggs",
"givenName": "Joe",
"surname": "Bloggs",
"userPrincipalName": "joe.bloggs@gmail.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": false,
"password": "somepassword"
}
}
响应:
{
"error": {
"code": "Request_BadRequest",
"message": "Property userPrincipalName is invalid.",
"innerError": {
"request-id": "619450ec-e703-4a12-86e3-8f53c20d55fc",
"date": "2018-01-17T16:30:37"
},
"details": [
{
"target": "userPrincipalName",
"code": "InvalidValue"
}
]
}
}
说"userPrincipalName"无效,但是看了文档后我不确定API是否支持外部账户?
注意:我知道您可以使用“/beta/invitations”调用,但这不会创建帐户。
我假设你正在使用 Azure AD B2B 并希望将新的来宾用户添加到你的目录。
我想说明的一件事是,您可以邀请来宾用户加入您的目录,但您不能直接在您的目录中创建来宾用户。
因此,您可以使用 this Microsoft Graph API:
邀请来宾用户请求
POST https://graph.microsoft.com/beta/invitations
Content-type: application/json
Content-length: 551
{
"invitedUserEmailAddress": "yyy@test.com",
"inviteRedirectUrl": "https://myapp.com"
}
回应
HTTP/1.1 201 OK
Content-type: application/json
Content-length: 551
{
"id": "7b92124c-9fa9-406f-8b8e-225df8376ba9",
"inviteRedeemUrl": "https://invitations.microsoft.com/redeem/?tenant=04dcc6ab-388a-4559-b527-fbec656300ea&user=7b92124c-9fa9-406f-8b8e-225df8376ba9&ticket=VV9dmiExBsfRIVNFjb9ITj9VXAd07Ypv4gTg%2f8PiuJs%3d&lc=1033&ver=2.0",
"invitedUserDisplayName": "yyy",
"invitedUserEmailAddress": "yyy@test.com",
"sendInvitationMessage": false,
"invitedUserMessageInfo": {
"messageLanguage": null,
"ccRecipients": [
{
"emailAddress": {
"name": null,
"address": null
}
}
],
"customizedMessageBody": null
},
"inviteRedirectUrl": "https://myapp.com/",
"status": "Completed",
"invitedUser": [ { "id": "243b1de4-ad9f-421c-a933-d55305fb165d" } ]
}
另外,如果您想在没有邀请的情况下邀请来宾用户,请参考this document。
希望对您有所帮助!