Reputation: 21
I have been having this issue for days and have not been able to figure out what it is.
In my Blazor WASM Standalone program I Handle Authentication with Azure Active directory and followed these exact steps to set it up: 1
It worked great locally out of the box, but after publishing it form Azure DevOps to the Static Web App Service of Azure the Authentication redirect simply stopped working, after looking at the requests the site is making with Fiddler, it is obvious that the redirect to Microsofts authentication site never happens.
Interestingly there is no authentication error message in the URL of the call back (as I was usually getting them when something was wrong) - there simply is no information, and the pop-out window does not even open too. Here is the only error Message that I get from the browser console.
Deployment to Azure Static App works just like in this tutorial 2 and here is my DevOps pipeline yaml in case it helps.
# Example Taken From https://reddit.fun/96630/devops-pipeline-unable-deploy-blazor-static-package-private
# research documentation https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-6.0#standalone-deployment
# Documentation of Azure Static Web App Task https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/azure-static-web-app?view=azure-devops
trigger:
- main
pool:
vmImage: ubuntu-latest
variables:
buildConfiguration: 'Release'
dotNetFramework: 'net6.0'
dotNetVersion: '6.0.x'
steps:
- checkout: self
submodules: true
- task: UseDotNet@2
inputs:
version: $(dotNetVersion)
includePreviewVersions: true
- task: CmdLine@2
inputs:
script: "dotnet workload install wasm-tools"
- task: DotNetCoreCLI@2
displayName: "dotnet restore"
inputs:
command: restore
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: "Publish Blazor App"
inputs:
command: publish
publishWebProjects: true #required for publish
arguments: '--configuration $(buildConfiguration) --framework $(dotNetFramework) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: false
- task: DownloadPipelineArtifact@2
displayName: "Download Artifacts"
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
- bash: cd $(Build.ArtifactStagingDirectory); echo $(ls); cd 'KapaBlazorWeb'; echo $(ls);
- task: AzureStaticWebApp@0
inputs:
cwd: $(Build.ArtifactStagingDirectory)
skip_app_build: true # skip build because restore of build will probably fail?!
app_location: '[BlazorAppName]/wwwroot'
azure_static_web_apps_api_token: '[TOKEN]]'
My question is, if you have had anything similar happen and if you know a way to fix this as I am very new to working with Azure and have never worked with Azures Static Webservice. Maybe the issue is not with the Blazor-App itself but with the Static-App-Service? Is there anything I could have missed? Is there a way to see more information about what is happening on the ASW?
EDIT: Update I also published the default Blazor Wasm AAD project (also standalone) as it is generated by the Visual studio template, and again locally it works great but when on the Static Web Service by Azure, the Redirect to Microsofts authentication page never happens, it always goes to the '/authentication/login-failed' path.
I am guessing that the IIS Server has some kind of configuration issue that I haven't been able to find yet.
Upvotes: 0
Views: 633
Reputation: 21
OK so I finally found the issue, and I want to leave it here:
After testing everything with the default Blazor AAD Template I at least got an Error which turns out to be answered in this question:
Then I just added these three rows to the csprj file (DIRECTLY UNDERNEATH the Itemgroup that contains all PackageReferences)
<ItemGroup>
<TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" />
</ItemGroup>
It now just magically works - apparently because this package gets trimmed in the publishing process which leads to issues down the line.
Hope it helps someone in the future :)
Upvotes: 2