I want to delete azure ad b2c user from azure ad b2c portal, iam using graph api for this purpose. So Manually registered an application in azure ad b2c portal and set permission to application.See below
and its working fine.Then i tried to automate the app registration through graph api and set the permission then the app permission is look like below. type application is changed to deletegated. And i can't delete to the user through graph api due to insufficient permission .BELOW IS MY CODE to grant the permission. (POWER SHELL)
STEPS
- Created an application manually and added some permissions(Application.ReadWrite.All,Application.ReadWrite.OwnedBy,Directory.ReadWrite.All,Policy.ReadWrite.TrustFramework,TrustFrameworkKeySet.Read.All,TrustFrameworkKeySet.ReadWrite.All,User.Read.All)
- Then i write below script using above created application client id and client secret(for calling graph api).
$tenantid ='xxxxxxxxxxxxxxxx' $appid='xxxxxxxxxxxxxxxxxxxx' $appsecret = 'xxxxxxxxxxxxxxxx' $Uri = 'https://login.microsoftonline.com/' + $tenantid +'/oauth2/v2.0/token' $Form = @{ client_id = $appid scope = 'https://graph.microsoft.com/.default' client_secret = $appsecret grant_type = 'client_credentials' } $Result = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form -contenttype 'application/json' $access_token=$Result.access_token $url = 'https://graph.microsoft.com/v1.0/applications' $headers = @{Authorization = "Bearer $access_token" } $method = "Post" $json = $bodyjsonstring | ConvertFrom-Json | ConvertTo-Json -Depth 10 $response = Invoke-RestMethod -Uri $url -Body $json -Method $method -Headers $headers -contenttype 'application/json'
- Then set a service principle for app
$appId = $response.appId $urlforappsp = 'https://graph.microsoft.com/v1.0/serviceprincipals' $dataforsp = '{ "appId": "' + $appId + '", }' $headers = @{Authorization = "Bearer $access_token" } $method = "Post" $json = $bodyjsonstring | ConvertFrom-Json | ConvertTo-Json -Depth 10 # Write-Host $json $response = Invoke-RestMethod -Uri $urlforappsp -Body $json -Method $method -Headers $headers -contenttype 'application/json' $responsesp = HTTP_POST_CALL -bearer_token $accesstoken -url $urlforappsp -bodyjsonstring $dataforsp
4.Then i call the link
response is
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications/$entity",
"id": "xxxxxxxxx",
"deletedDateTime": null,
"appId": "xxxxxxxx",
"applicationTemplateId": null,
"createdDateTime": "2020-12-14T18:23:26Z",
"displayName": "userapp",
"description": null,
"groupMembershipClaims": null,
"identifierUris": [],
"isDeviceOnlyAuthSupported": null,
"isFallbackPublicClient": null,
"notes": null,
"optionalClaims": null,
"publisherDomain": "xxxxxxxxxxxx",
"signInAudience": "AzureADMyOrg",
"tags": [],
"tokenEncryptionKeyId": null,
"verifiedPublisher": {
"displayName": null,
"verifiedPublisherId": null,
"addedDateTime": null
},
"spa": {
"redirectUris": []
},
"defaultRedirectUri": null,
"addIns": [],
"api": {
"acceptMappedClaims": null,
"knownClientApplications": [],
"requestedAccessTokenVersion": null,
"oauth2PermissionScopes": [],
"preAuthorizedApplications": []
},
"appRoles": [],
"info": {
"logoUrl": null,
"marketingUrl": null,
"privacyStatementUrl": null,
"supportUrl": null,
"termsOfServiceUrl": null
},
"keyCredentials": [],
"parentalControlSettings": {
"countriesBlockedForMinors": [],
"legalAgeGroupRule": "Allow"
},
"passwordCredentials": [],
"publicClient": {
"redirectUris": []
},
"requiredResourceAccess": [],
"web": {
xxxxx
}
}
}
requiredResourceAccess and approle are empty.then how do i call
"/appRoleAssignedTo"