C
C#•2y ago
malkav

Authentication Flow Blazor

Can someone help me understand the Blazor Authentication flow, I want to call the database and set the user into a LoggedInUserState, but the <Authentication Action=@Action /> component has some strange order of business, I want to wait till the login process is done, then make the user wait while fetching data, so I can call the graph, then when that's done, call the database, and store graph data in the user if it doesn't already exist, and then set that user in the state. but right now what I see in the console is:
GET graph.me (401) GET graph.me (success) GET login.microsoft.com/token/v2.0/.well-known/openid-configuration GET graph.me.photo.$value (401) GET graph.me.photo.$value (success) GET databaseCall (without graph.me.Id, so I am missing a step apparently) Unexpected character encountered while parsing value: <. Path: '', line 0, position 0 POST login.microsoft.com/token/oauth2/v2.0/token Object reference not set to instance of object (which is kind of obvious as there hasn't been a user set to LoggedInUserState yet)
So how can I best approach this? I've got the GraphServiceClient setup as per the Blazor examples, as well as the UserClaimsBase, and the UserProfileBase, which I've chained together because I need to call the ClaimsBase first, and then the ProfileBase to set the User from the graph, and then I can use that ID to actually start working on the rest. But right now there's something wrong with the flow, and I can't figure out where the flow starts or ends 😅 help please https://github.com/Azure-Samples/ms-identity-blazor-wasm/tree/main/WebApp-graph-user/Call-MSGraph/blazorwasm-calls-MS-graph Git repo for reference.
1 Reply
malkav
malkav•2y ago
I've setup the GraphExtensionClient class, and I've currently got the UserClaimsBase as well as the UserProfileBase extended to the <Authentication /> component in the following order:
UserClaimsBase : ComponentBase UserProfileBase : UserClaimsBase
Both these call their OnInitializedAsync() method in order, await UserClaimsBase.OnInitializedAsync() > await UserProfileBaseOnInitializedAsync() > await Authentication.razor.OnInitializedAsync() I did however extend the UserProfileBase class to also include a property for the User's Photo graph/me/photo/$value because I had to store it as a base64 string, but that's not the point