internal void open() { logger.Debug("Open Session"); // build uri UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Scheme = properties[SFSessionProperty.SCHEME]; uriBuilder.Host = properties[SFSessionProperty.HOST]; uriBuilder.Port = Int32.Parse(properties[SFSessionProperty.PORT]); uriBuilder.Path = SF_LOGIN_PATH; var queryString = HttpUtility.ParseQueryString(string.Empty); string value; queryString[SF_QUERY_WAREHOUSE] = properties.TryGetValue(SFSessionProperty.WAREHOUSE, out value) ? value : ""; queryString[SF_QUERY_DB] = properties.TryGetValue(SFSessionProperty.DB, out value) ? value : ""; queryString[SF_QUERY_SCHEMA] = properties.TryGetValue(SFSessionProperty.SCHEMA, out value) ? value : ""; queryString[SF_QUERY_REQUEST_ID] = Guid.NewGuid().ToString(); uriBuilder.Query = queryString.ToString(); // build post body AuthnRequestClientEnv clientEnv = new AuthnRequestClientEnv() { application = System.Diagnostics.Process.GetCurrentProcess().ProcessName, osVersion = System.Environment.OSVersion.VersionString }; AuthnRequestData data = new AuthnRequestData() { loginName = properties[SFSessionProperty.USER], password = properties[SFSessionProperty.PASSWORD], clientAppId = ".NET", clientAppVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), accountName = properties[SFSessionProperty.ACCOUNT], clientEnv = clientEnv }; // build request int connectionTimeoutSec = Int32.Parse(properties[SFSessionProperty.CONNECTION_TIMEOUT]); SFRestRequest loginRequest = new SFRestRequest(); loginRequest.jsonBody = new AuthnRequest() { data = data }; loginRequest.uri = uriBuilder.Uri; loginRequest.authorizationToken = SF_AUTHORIZATION_BASIC; // total login timeout loginRequest.sfRestRequestTimeout = connectionTimeoutSec <= 0 ? -1 : connectionTimeoutSec * 1000; if (logger.IsTraceEnabled) { logger.TraceFormat("Login Request Data: {0}", loginRequest.ToString()); } JObject response = restRequest.post(loginRequest); parseLoginResponse(response); }
private SFRestRequest BuildLoginRequest() { // build uri var queryParams = new Dictionary <string, string>(); string warehouseValue; string dbValue; string schemaValue; string roleName; queryParams[SF_QUERY_WAREHOUSE] = properties.TryGetValue(SFSessionProperty.WAREHOUSE, out warehouseValue) ? warehouseValue : ""; queryParams[SF_QUERY_DB] = properties.TryGetValue(SFSessionProperty.DB, out dbValue) ? dbValue : ""; queryParams[SF_QUERY_SCHEMA] = properties.TryGetValue(SFSessionProperty.SCHEMA, out schemaValue) ? schemaValue : ""; queryParams[SF_QUERY_ROLE] = properties.TryGetValue(SFSessionProperty.ROLE, out roleName) ? roleName : ""; queryParams[SF_QUERY_REQUEST_ID] = Guid.NewGuid().ToString(); var loginUri = BuildUri(SF_LOGIN_PATH, queryParams); AuthnRequestData data = new AuthnRequestData() { loginName = properties[SFSessionProperty.USER], password = properties[SFSessionProperty.PASSWORD], clientAppId = ".NET", clientAppVersion = _EnvironmentData.Item2, accountName = properties[SFSessionProperty.ACCOUNT], clientEnv = _EnvironmentData.Item1 }; int connectionTimeoutSec = int.Parse(properties[SFSessionProperty.CONNECTION_TIMEOUT]); return(new SFRestRequest() { jsonBody = new AuthnRequest() { data = data }, uri = loginUri, authorizationToken = SF_AUTHORIZATION_BASIC, sfRestRequestTimeout = connectionTimeoutSec > 0 ? TimeSpan.FromSeconds(connectionTimeoutSec) : Timeout.InfiniteTimeSpan }); }