/// <summary> /// Connects to the Dataverse API for the given SQL connection /// </summary> /// <returns></returns> protected CrmServiceClient ConnectCDS(SqlConnectionStringBuilder conStr) { if (conStr == null) { return(null); } var server = conStr.DataSource.Split(',')[0]; if (_clientCache.TryGetValue(server, out var con)) { return(con.Clone()); } var resource = $"https://{server}/"; var req = WebRequest.CreateHttp(resource); req.AllowAutoRedirect = false; var resp = req.GetResponse(); var authority = new UriBuilder(resp.Headers[HttpResponseHeader.Location]); authority.Query = ""; authority.Port = -1; var authParams = new AuthParams(conStr.Authentication, server, conStr.InitialCatalog, resource, authority.ToString(), conStr.UserID, "", Guid.Empty); AuthOverrideHook.Instance.AddAuth(authParams); con = new CrmServiceClient(new Uri(resource), true); _clientCache[server] = con; return(con.Clone()); }
public void AddAuth(AuthParams authParams) { _authParams[authParams.Resource] = authParams; }