2

在 Azure 门户中,我可以为 Graph 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

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

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

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

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

4

1 回答 1

2

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

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

希望这可以帮助

于 2015-03-14T00:10:38.830 回答