Inheritance: SqlAuthenticationParameters
コード例 #1
0
ファイル: CommandBase.cs プロジェクト: MarkMpn/Sql4Cds
        /// <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());
        }
コード例 #2
0
ファイル: AuthOverrideHook.cs プロジェクト: MarkMpn/Sql4Cds
 public void AddAuth(AuthParams authParams)
 {
     _authParams[authParams.Resource] = authParams;
 }