New-AzADAppCredential Generate Client Secret

喜欢而已 提交于 2020-08-11 03:13:10

问题


Is there a way to generate a password client secret using the New-AzADAppCredential cmdlet? I don't want to supply the password to the cmdlet and would much rather use the generate one much like the Azure Portal.


回答1:


I am afraid you can't, when using New-AzADAppCredential to create client secret, the -Password is needed.

The workaround is to use the New-AzureADApplicationPasswordCredential command in AzureAD module.

New-AzureADApplicationPasswordCredential -ObjectId "<object-id>"




回答2:


Not natively, but you can create a very similar client secret using the same tools that generate them in the portal.

It's not as elegant as having the solution baked into the cmdlet, but it works very well.

$bytes = New-Object Byte[] 32
$rand = ([System.Security.Cryptography.RandomNumberGenerator]::Create()).GetBytes($bytes)
$ClientSecret = [System.Convert]::ToBase64String($bytes) | ConvertTo-SecureString -AsPlainText -Force

$endDate = [System.DateTime]::Now.AddYears(1)
New-AzADAppCredential -ObjectId "<object-id>" -Password $ClientSecret -startDate $(get-date) -EndDate $endDate


来源:https://stackoverflow.com/questions/59038203/new-azadappcredential-generate-client-secret

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!