我第一次尝试使用 MSAL 授权,但在 Blazor 中失败了。任何线索(我认为这将是一个简单的答案?)
此处提供小型仓库
客户端文件:Program.cs
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddMsalAuthentication(options => //THROWS EXCEPTION!!!!!
{
options.ProviderOptions.AdditionalScopesToConsent.Add($"https://graph.microsoft.com/User.Read");
});
var baseAddress = builder.HostEnvironment.BaseAddress;
builder.Services.AddHttpClient(baseAddress, client => client.BaseAddress = new Uri(baseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
Run Code Online (Sandbox Code Playgroud)
意外结果:抛出异常
暴击:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常渲染组件:无法读取未定义的属性“join” TypeError:无法读取 Function.createUserManager 处未定义的属性“join”(https://localhost:44391/ _content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js:1:6020)在 Function.initializeCore (https://localhost:44391/_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js:1 :5035 ) 在 Function.init ( https://localhost:44391/_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js:1:4575 ) 在https://localhost:44391/_framework/blazor.web assembly .js:1:9873 在 Object.beginInvokeJSFromDotNet ( https://localhost:44391/_framework/blazor.web assembly.js:1:9841 ) 的新 Promise () 在 _mono_wasm_invoke_js_marshalled ( https://localhost:44391/_framework/wasm) /dotnet.3.2.0.js:1:171294 ) 在 do_icall (wasm-function[6049]:0x10f8b1) 在 do_icall_wrapper (wasm-function[1896]:0x50b6a) 在 interp_exec_method (wasm-function[1120]:0x2588e)