使用Microsoft Graph使用addpassword方法更新应用程序passwordCredentials

时间:2019-09-17 14:34:53

标签: microsoft-graph

我正在更改Powershell脚本,以更新应用程序的passwordCredentials(特别是keyId,secretText和Hint),就像以前我们使用PATCH一样,但是现在已经按照https://developer.microsoft.com/en-us/graph/blogs/breaking-changes-application-and-serviceprincipal-api-updates-in-microsoft-graph-beta/

进行了更改

但是,当我使用POST时,我似乎似乎无法再更新KeyId,secretText和Hint,这在PATCH上仍然可以使用,但是在此之前,我一直想更新我的代码,您能帮忙吗?

此代码目前仍然有效:

$jsonData = '
{
 "passwordCredentials": [
  {
  "customKeyIdentifier": null,
  "endDateTime": "2119-05-01T10:18:33.4995826Z",
  "keyId": "'+ $($guid) +'",
  "startDateTime": "2019-05-01T10:18:33.4995826Z",
  "secretText": "'+ $($Password.Password) +'",
  "hint": "'+ $($Passwordhint) +'"
  }
 ]
}'

#Specify the URI to call and method
$uri = "https://graph.microsoft.com/beta/applications/$ID/"
$method = "PATCH"
Invoke-WebRequest -Method $method -Uri $uri -ContentType "application/json" -Body $jsonData -Headers @{Authorization = "$($global:authtoken.authorization)"} -ErrorAction Stop | Out-Null

以下内容执行POST,但创建的密码没有提供任何信息,密码凭据未按预期更新该应用程序:

#Populate JSON data for the application
$jsonData = '
{
 "passwordCredentials": [
  {
  "customKeyIdentifier": null,
  "endDateTime": "2119-05-01T10:18:33.4995826Z",
  "keyId": "'+ $($guid) +'",
  "startDateTime": "2019-05-01T10:18:33.4995826Z",
  "secretText": "'+ $($Password.Password) +'",
  "hint": "'+ $($Passwordhint) +'"
  }
 ]
}'

#Specify the URI to call and method
$uri = "https://graph.microsoft.com/beta/applications/$ID/addPassword"
$method = "POST"
Invoke-WebRequest -Method $method -Uri $uri -ContentType "application/json" -Body $jsonData -Headers @{Authorization = "$($global:authtoken.authorization)"} -ErrorAction Stop | Out-Null

1 个答案:

答案 0 :(得分:0)

似乎https://graph.microsoft.com/beta/$metadata中的addPassword操作具有一个包装的passwordCredential作为参数:

...
<Action Name="addPassword" IsBound="true">
<Parameter Name="bindingParameter" Type="microsoft.graph.application" Nullable="false"/>
<Parameter Name="passwordCredential" Type="microsoft.graph.passwordCredential"/>
<ReturnType Type="microsoft.graph.passwordCredential" Nullable="false"/>
</Action>
...

这样的POST正文:

{
  "passwordCredential": {
    "customKeyIdentifier": null,
    "endDateTime": "2119-05-01T10:18:33.4995826Z",
    "startDateTime": "2019-05-01T10:18:33.4995826Z",
    "displayName": "new test password"
  }
}

应返回生成的凭证,例如:

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#microsoft.graph.passwordCredential",
    "customKeyIdentifier": null,
    "endDateTime": "2119-05-01T10:18:33.4995826Z",
    "keyId": "...",
    "startDateTime": "2019-05-01T10:18:33.4995826Z",
    "secretText": "...",
    "hint": "...",
    "displayName": "new test password"
}