-
Notifications
You must be signed in to change notification settings - Fork 176
Description
AL-Go version
8.0
Describe the issue
I will preface this report that I'm not sure if this is an AL-Go Documentation issue or a BcContainerHelper issue.
I have an AppSource app that I wanted to deploy to a Sandbox environment from within AL-Go and so followed the guide here https://github.com/microsoft/AL-Go/blob/main/Scenarios/RegisterSandboxEnvironment.md
I followed all the steps in that guide, which can be summarised as
- Create App Registration
- Create App Registration Secret
- Add API permissions
- Add App Registration Client ID to Entra Apps page in the BC environment I am deploying to.
- Create Environment Secret in GitHub Repo with AuthContext
- Run AL-Go Publish to Environment action.
However, when Running the Publish to Environment action it consistently failed with
Error: Deploying to SandboxAUv27 failed. The remote server returned an error: (401) Unauthorized. Unauthorized
I won't include ALL the things I tried to get this going and instead will short cut to the end.
It was eventually resolved by including the following API permission in my App Registration

And then making sure my App Registration was also added to the Micrsoft Entra Apps page of my tenant in BS Admin Center.

These additional steps are not listed in any of the support documents or AL-Go Scenarios that I could find.
BUT why did it break at all? In theory it doesn't need Admin Center API permissions, as I am deploying direct to the environment and not going anywhere near BC Admin Center.
Well as it turns out, in my situation, not quite.
My app is an AppSource app with a dependency on another AppSource app (both my own). Due to this dependency the Publish to Environment action elects to source the dependent app from AppSource instead of using the appDependencyProbingPaths setting in .AL-Go/settings.json.
Consequently, it calls the BcContainerHelper module Install-BcAppFromAppSource which internally calls Get-BcEnvironments which queries the BC Admin Center for a list of environments. And without my App Registration granted permission in BC Admin Center, it fails with The remote server returned an error: (401) Unauthorized. Unauthorized.
Which raise the following 2 questions.
- Why does AL-Go opt to install an AppSource dependency from AppSource instead of utilising the appDependencyProbingPaths setting in .AL-Go/settings.json.?
- Why, after specifying the environment to connect to, does Install-BcAppFromAppSource powershell module need to query the list of environments at all?
Expected behavior
I was expecting AL-Go to utilise the appDependencyProbingPaths property to source the artifact to install into the environment. It does this correctly when building the app via CI/CD workflow. Perhaps it was my misunderstanding that led me to thinking that "Publish To Environment" workflow would behave the same way.
I am also expecting that the error returned in the workflow run would be more helpful. As it is, it just says there was an error. There was no indication about what service was rejecting the authorisation. Without that information, I assumed (incorrectly) I had configured my app registration or BC Entra App page incorrectly.
Steps to reproduce
Once I figured out where the permissions were failing, it was relatively easy to isolate and reproduce the problem directly in PowerShell.
Follow the steps outlined here https://github.com/microsoft/AL-Go/blob/main/Scenarios/RegisterSandboxEnvironment.md
Then using those details, plug the value into the below powershell and run to get the same error.
$authcontext = New-BcAuthContext `
-clientID '<Client ID>' `
-clientSecret '<Client Secret>' `
-tenantID '<BC Tenant>'
Install-BcAppFromAppSource `
-appId '<Any BC AppSource App ID>' `
-bcAuthContext $authcontext `
-environment '<BC Environment Name>'
After getting the error, go back to app registration and add AdminCenter.ReadWrite.All permission
Then add the Application (Client) ID to the Microsoft Entra Apps page in BC Admin Center
Then when you re-run the powershell. It will succeed. At this point (assuming AL-Go app is using the same App Registration details and environment), it too will succeed.
Additional context (logs, screenshots, etc.)
Here are the logs of the failed run for reference.
logs_49270650009.zip
URL to failed run
https://github.com/BW-PA/AppSourceApp1/actions/runs/19130334193/job/54669380974#step:7:71
Here are the Public Repos I setup to reproduce the issue prior to figuring out how to reproduce via powershell directly. 1 is the primary app and has a dependency on 2. Note that neither are actually live on AppSource. So once the (401) Unauthorized error is resolved it gets App not found on AppSource error (which is expected)