/// <summary> /// Returns a CSOM ClientContext for a given PnP Core SDK context /// </summary> /// <param name="pnpContext">The PnP Core SDK context</param> /// <returns>The equivalent CSOM ClientContext</returns> public ClientContext GetClientContext(PnPContext pnpContext) { #pragma warning disable CA2000 // Dispose objects before losing scope AuthenticationManager authManager = AuthenticationManager.CreateWithPnPCoreSdk(pnpContext); #pragma warning restore CA2000 // Dispose objects before losing scope var ctx = authManager.GetContext(pnpContext.Uri.ToString()); var ctxSettings = ctx.GetContextSettings(); ctxSettings.AuthenticationManager = authManager; //otherwise GetAccessToken would not work for example ctx.AddContextSettings(ctxSettings); return(ctx); }
/// <summary> /// Returns a CSOM ClientContext for a given PnP Core SDK context /// </summary> /// <param name="pnpContext">The PnP Core SDK context</param> /// <returns>The equivalent CSOM ClientContext</returns> public async Task <ClientContext> GetClientContextAsync(PnPContext pnpContext) { #pragma warning disable CA2000 // Dispose objects before losing scope AuthenticationManager authManager = AuthenticationManager.CreateWithPnPCoreSdk(pnpContext); #pragma warning restore CA2000 // Dispose objects before losing scope var ctx = await authManager.GetContextAsync(pnpContext.Uri.ToString()).ConfigureAwait(false); var ctxSettings = ctx.GetContextSettings(); ctxSettings.Type = Utilities.Context.ClientContextType.PnPCoreSdk; ctxSettings.AuthenticationManager = authManager; //otherwise GetAccessToken would not work for example ctx.AddContextSettings(ctxSettings); return(ctx); }