Blazor Server GraphServiceClient

Matthew Holton 331 Reputation points
2023-04-24T14:36:03.8533333+00:00

I am looking enable MicrosoftGraph in my Blazor server hosted application.
From what I gather, I am no longer able to simply use .AddMicrosoftGraph because IAuthencationProvidedr is no longer available. Beyond that, the docs aren't real clear as to what I am supposed to do.
Creating an instance of GraphServiceClient using AddMicrosoftGraph produces an error: Cannot load Type Microsoft.Graph.IAuthenticationProviderOption. Creating an instance of GraphServiceClient using InteractiveBrowserCredential produces an error: AADST65002. intended usage: public class UserManagerService{ public UserManagerService(DatabaseAccess access, GraphServiceClient graphClient){...} public void CreateGuestAccount(GuestAccountInfo info){ //Check has guest create permission in AD //Create invitation in AD //Create guest user in AD //Map user in database } } Anyone have any guidance on this? See: https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/upgrade-to-v5.md

Developer technologies ASP.NET ASP.NET Core
Developer technologies .NET Blazor
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-04-24T16:04:03.7966667+00:00

    GraphApi uses oauth access tokens. To call graph api you need to register your server application:

    https://learn.microsoft.com/en-us/graph/auth-register-app-v2

    Depending on the use case:

    the blazor app can registered with a service account, and have its own access token and permission:

    https://learn.microsoft.com/en-us/graph/auth-v2-service

    the blazor app can be registered and use the users access token.

    https://learn.microsoft.com/en-us/graph/auth-v2-user

    sample using REST api rather than client sdk (but you can use the sdk)

    https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-blazor-server.

    note: when using Microsoft identity with blazor server, the authentication is done outside the blazor app by .net core middleware. the token will be stored in a cache. if on a webform, you will need a distributed cache.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.