Get-MsalToken 错误 AADSTS7000218:请求正文必须包含以下参数:'client_assertion' 或 'client_secret'

问题描述 投票:0回答:2

这是我的 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
2个回答
13
投票

请参阅公开客户和机密客户申请之间的区别

机密客户端应用程序可以安全地保守应用程序的秘密,而公共客户端则不然。

所以你遇到的错误说明你的app注册是Confidential client application(创建时选择了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 [email protected]
    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).

-4
投票
© www.soinside.com 2019 - 2024. All rights reserved.