Create Azure AD ClientCredentials Key from PowerShell



在 Azure 门户中,我可以创建图形 API 的应用程序、密钥和权限。

我可以使用以下方法获取令牌:

AuthenticationContext ac = new AuthenticationContext("https://login.windows.net/graphDir1.onmicrosoft.com");
ClientCredential cc = new ClientCredential("b3b1fc59-84b8-4400-a715-ea8a7e40f4fe", "FStnXT1QON84B5o38aEmFdlNhEnYtzJ91Gg/JH/Jxiw=");
AuthenticationResult authResult = ac.AcquireToken("https://graph.windows.net", cc);

使用 Windows PowerShell 的 Azure Active Directory 模块,我可以创建一个新的对称密钥。

New-MsolServicePrincipalCredential -AppPrincipalId ??? -Type Symmetric

在上面的代码中使用从中返回的键返回错误:

AdalServiceException: AADSTS70002: Error validating credentials. AADSTS50012: Invalid client secret is provided.

这曾经使用以前版本的ADAL而不是ClientCredentialSymmetricKeyCredential但该类不再存在。

有没有办法从PowerShell生成与上述代码一起使用的密钥?

请尝试使用Password作为密钥类型:

New-MsolServicePrincipalCredential -AppPrincipalId $appId `
                                   -Type Password `
                                   -StartDate ([DateTime]::Now.AddMinutes(-5)) `
                                   -EndDate ([DateTime]::Now.AddMonths(1)) `
                                   -Value "$newPassword"

希望这有帮助

最新更新