private static ClientContext CreateContext(string contextUrl, ICredentials credentials) { ClientContext context; if (!String.IsNullOrEmpty(Realm) && !String.IsNullOrEmpty(AppId) && !String.IsNullOrEmpty(AppSecret)) { AuthenticationManager am = new AuthenticationManager(); context = am.GetAppOnlyAuthenticatedContext(contextUrl, Realm, AppId, AppSecret); } else { context = new ClientContext(contextUrl); context.Credentials = credentials; } return context; }
private static ClientContext CreateContext(string contextUrl, ICredentials credentials) { ClientContext context; if (!String.IsNullOrEmpty(AppId) && !String.IsNullOrEmpty(AppSecret)) { AuthenticationManager am = new AuthenticationManager(); if (new Uri(DevSiteUrl).DnsSafeHost.Contains("spoppe.com")) { context = am.GetAppOnlyAuthenticatedContext(contextUrl, Core.Utilities.TokenHelper.GetRealmFromTargetUrl(new Uri(DevSiteUrl)), AppId, AppSecret, acsHostUrl: "windows-ppe.net", globalEndPointPrefix:"login"); } else { context = am.GetAppOnlyAuthenticatedContext(contextUrl, AppId, AppSecret); } } else { context = new ClientContext(contextUrl); context.Credentials = credentials; } context.RequestTimeout = Timeout.Infinite; return context; }
public static PnPClientContext CreatePnPClientContext(int retryCount = 10, int delay = 500) { PnPClientContext context; if (!String.IsNullOrEmpty(AppId) && !String.IsNullOrEmpty(AppSecret)) { AuthenticationManager am = new AuthenticationManager(); ClientContext clientContext = null; if (new Uri(DevSiteUrl).DnsSafeHost.Contains("spoppe.com")) { clientContext = am.GetAppOnlyAuthenticatedContext(DevSiteUrl, Core.Utilities.TokenHelper.GetRealmFromTargetUrl(new Uri(DevSiteUrl)), AppId, AppSecret, acsHostUrl: "windows-ppe.net", globalEndPointPrefix: "login"); } else { clientContext = am.GetAppOnlyAuthenticatedContext(DevSiteUrl, AppId, AppSecret); } context = PnPClientContext.ConvertFrom(clientContext, retryCount, delay); } else { context = new PnPClientContext(DevSiteUrl, retryCount, delay); context.Credentials = Credentials; } context.RequestTimeout = Timeout.Infinite; return context; }