【问题标题】:Get-MsalToken error AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'Get-MsalToken 错误 AADSTS7000218:请求正文必须包含以下参数:“client_assertion”或“client_secret”
【发布时间】:2021-05-17 16:02:40
【问题描述】:

这是我的 PowerShell 脚本

$connectionDetails = @{
    'TenantId'    = '****-****'
    'ClientId'    = '****-****'
    'Interactive' = $true
    'Scopes' = '****-****'
    'RedirectUri' = '****-****'
}

$token = Get-MsalToken @connectionDetails

$accessToken = $token.AccessToken

write-output $accessToken

报错如下:

AADSTS7000218:请求正文必须包含以下参数:“client_assertion”或“client_secret”

为什么会出现此错误?我该如何解决?

【问题讨论】:

标签: powershell azure-active-directory msal


【解决方案1】:

请参阅the differences between public client and confidential client applications

机密客户端应用程序可以安全地保存应用程序机密,而公共客户端则不能。

所以你遇到的错误意味着你的应用注册是机密客户端应用(创建时选择Web)需要你提供ClientSecret,但你没有指定.

所以你有 2 个选项来解决它。

第一个是在您的脚本中提供ClientSecret不要在 Azure 门户上修改任何内容):

$connectionDetails = @{
    'TenantId'    = '****-****'
    'ClientId'    = '****-****'
    'ClientSecret'= '****-****'
    'Interactive' = $true
    'Scopes' = '****-****'
    'RedirectUri' = '****-****'
}

第二个是将您的应用注册从机密客户端应用程序更改为 Azure 门户上的公共客户端应用程序 -> 你的应用程序注册 -> 清单。 (不要修改你的脚本

Get-MsalToken.ps1 还包括 2 个示例:

.EXAMPLE
    PS C:\>Get-MsalToken -ClientId '00000000-0000-0000-0000-000000000000' -TenantId '00000000-0000-0000-0000-000000000000' -Interactive -Scope 'https://graph.microsoft.com/User.Read' -LoginHint user@domain.com
    Force interactive authentication to get AccessToken (with MS Graph permissions User.Read) and IdToken for specific Azure AD tenant and UPN using client id from application registration (public client).

.EXAMPLE
    PS C:\>Get-MsalToken -ClientId '00000000-0000-0000-0000-000000000000' -ClientSecret (ConvertTo-SecureString 'SuperSecretString' -AsPlainText -Force) -TenantId '00000000-0000-0000-0000-000000000000' -Scope 'https://graph.microsoft.com/.default'
    Get AccessToken (with MS Graph permissions .Default) and IdToken for specific Azure AD tenant using client id and secret from application registration (confidential client).

【讨论】:

  • 我很好奇为什么你建议在 Manifest 部分而不是通过 Authentication 部分的 UI 来更改它?当 Microsoft 提供了一个按钮/切换选项,您可以单击以将其设置为 true,为什么还要冒出现拼写错误或转录错误的风险?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-05
  • 2015-12-29
  • 2021-11-22
相关资源
最近更新 更多