I have an Azure B2C tenant and an application registered within it. I need to generate a new application secret, and I'd like to do it programmatically using PowerShell and authenticate to b2c with the current secret value. Is that even possible?
I've found some documentation on managing Azure AD applications with PowerShell, but I'm not sure how to generate a new application secret specifically for Azure B2C.
Try it but I got stuck with that error. Here are my samples
$AppSecretDescription = "TestSecret"
$AppYears = "2"
$azureAplicationId ="ApplicationId"
$azureTenantId= "myTenantid"
$azurePassword = ConvertTo-SecureString "MySecretValue" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
$aadToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, "https://graph.windows.net").AccessToken
Connect-AzureAD -AadAccessToken $aadToken -AccountId $context.Account.Id -TenantId $context.tenant.id
$StartDate = Get-Date
$EndDate = $StartDate.AddYears($AppYears)
$AppClientSecret = New-AzureADApplicationPasswordCredential -CustomKeyIdentifier clientsecret -ObjectId $AppObjectID -EndDate ((Get-Date).AddMonths(24))
Write-Host $AppClientSecret.Value
Error receive
Code: Request_ResourceNotFound
Message: Resource 'Applicationid' does not exist or one of its queried reference-property objects are not present.
Try it with objectId principal Id. How can I achieve this, the main goal is to automatically create secrets in different directories at a certain time in Azure DevOps Pipeline.