/// <summary> /// Constructor /// </summary> /// <param name="authManager">The authorization manager to use.</param> /// <param name="connectionInfo">Connection Information</param> internal HttpService(ApiAuthManager authManager, ConnectionInfo connectionInfo) { if (authManager == null) { throw new ArgumentNullException("authManager"); } if (connectionInfo == null) { throw new ArgumentNullException("connectionInfo"); } this.authManager = authManager; this.connectionInfo = connectionInfo; if (connectionInfo.AuthType == AuthorizationType.Basic) { Server = connectionInfo.Server; credentials = new CredentialCache { { connectionInfo.Server, "Basic", new NetworkCredential(connectionInfo.UserName, connectionInfo.Password) } }; } else if (connectionInfo.AuthType == AuthorizationType.ZSessionID) { Server = connectionInfo.Server; credentials = null; } else if (connectionInfo.AuthType == AuthorizationType.ApiKey) { Server = connectionInfo.Server; credentials = new CredentialCache { { connectionInfo.Server, "Basic", new NetworkCredential(connectionInfo.ApiKey, connectionInfo.ApiKey) } }; } }
// HELP: This method has some setup code that may interest you. #region reconfigure_Click private void reconfigure_Click(object sender, RoutedEventArgs e) { Uri defaultProxyServer = null; if (!String.IsNullOrWhiteSpace(defaultProxyServerUri.Text)) { defaultProxyServer = new Uri(defaultProxyServerUri.Text); } // HELP: This is for demo purposes only. We are clearing all known data in the authentication managers by doing this. winFormsAuthMgr = new RestApiAuthMgrWinforms(applicationToken, encryptionKey, encryptionUtilities); wpfAuthMgr = new RestApiAuthMgrWpf(applicationToken, encryptionKey, encryptionUtilities); UpdateAuthenticationResults(RallyRestApi.AuthenticationResult.NotAuthorized, null); // HELP: Configure labels for UI. These are global and used by both authentication managers to build their UI. // If this is not called, the default labels will be used. ApiAuthManager.Configure(loginWindowServerLabelText: "My Updated Server Label", loginWindowDefaultServer: new Uri("http://onprem.rally.url")); Uri defaultServer = null; if (!String.IsNullOrWhiteSpace(defaultServerUri.Text)) { defaultServer = new Uri(defaultServerUri.Text); } ApiAuthManager.Configure(windowTitleLabel.Text, headerLabel.Text, credentialsTabLabel.Text, usernameLabel.Text, passwordLabel.Text, serverTabLabel.Text, String.Empty, serverLabel.Text, String.Empty, defaultServer, proxyTabLabel.Text, proxyServerLabel.Text, proxyUsernameLabel.Text, proxyPasswordLabel.Text, defaultProxyServer, loginWindowSsoInProgressLabel.Text, loginButtonLabel.Text, logoutButtonLabel.Text, cancelButtonLabel.Text); // HELP: If you need to use custom controls (Ex: from a third party vendor), you can set them using this code snippet. // This triggers a global change for the next time a window is created. if ((useCustomControls.IsChecked.HasValue) && (useCustomControls.IsChecked.Value)) { RestApiAuthMgrWpf.SetCustomControlType(CustomWpfControlType.Buttons, typeof(CustomButton)); RestApiAuthMgrWpf.SetCustomControlType(CustomWpfControlType.TabControl, typeof(CustomTabControl)); RestApiAuthMgrWpf.SetCustomControlType(CustomWpfControlType.TabItem, typeof(CustomTabItem)); } }