blazor-server-aad-sample
blazor-server-aad-sample copied to clipboard
Obsolete AzureAd References
Hi
I have successfully implemented the sample code on a local project and am able to retrieve the bearer token via the WeatherForecast service class.
The references to AzureAd authentication schemes in startup.cs are flagged as obsolete by Visual Studio. I have attempted to update these references by searching for and applying code changes. Any changes from using AzureAd to OpenId or similar results in the token being returned as null,
What changes do I need to make to fix the obsolete warnings and keep this functionality working?
The attached screenshot shows the lines VS has flagged
Thanks
Mark

A further twist to the issue. If I change the Add Authentication call to the code below I can get the token:
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd")); //.EnableTokenAcquisitionToCallDownstreamApi(initialScopes) //.AddMicrosoftGraph(builder.Configuration.GetSection("MicrosoftGraph")) //.AddInMemoryTokenCaches();
If I un-comment those 3 lines to add Graph and external API support, it fails. And as you can see, I havent figured out how to maintain tabs in code snippets. Surely I dont have to resort to spaces?
So something in those calls is causing an issue.
I tried an alternative suggestion where intercepting OnTokenValidated event in the OpenIdEvents handler allows access to the token, but I could never get the OnTokenValidated event to actually fire.
So as a work around I am using HttpClient in Blazor code behind instead of the convenience of GraphServiceClient. More time consuming initially. The /communications/getPresencesByUserId call is especially fussy. Just one tiny little issue with the JSON you try to post and you will receive the dreaded "unsupported media type" error, which is not very helpful at all.
Where I need Graph access client side, for pulling images via the user/userid/photo API, I am using the fetch() method. A lot cleaner than the old XmlHttpRequest.
If anyone has any questions let me know. I'll continue cleaning and refining.
The app I am writing is in .Net 6/C#10. Global usings are a blessing and file based namespaces keep the code just that little bit more tidy.
Cheers