/// <summary> /// Get an authenticated Microsoft Graph Service client using the specified context /// </summary> /// <param name="graphClientContext">Defines the context for the GraphClient: User, Application or OnBehalf</param> /// <param name="userId">Optional: User identifier to get the token</param> /// <returns></returns> public GraphServiceClient GetAuthenticatedClient(GraphClientContext graphClientContext, string userId = "") { switch (graphClientContext.Name) { case "Application": return(GetAppServiceClient()); case "OnBehalf": return(GetOnBehalfServiceClient()); } // By default return current user context return(GetUserServiceClient(userId)); }
public GraphBaseService( ILogger <T> logger, IOptions <AppOptions> appOptions, IGraphAuthProvider authProvider, IUserContext userContext, IGraphClientContext graphClientContext) : base(logger, appOptions) { Guard.Against.Null(authProvider, nameof(authProvider)); Guard.Against.Null(userContext, nameof(userContext)); Guard.Against.Null(graphClientContext, nameof(graphClientContext)); _authProvider = authProvider; _userContext = userContext; // Set current context to User by default (always default to least privilege) _currentClientContext = GraphClientContext.User; }