/// <summary> /// Marks a user as 'signed out' of an Azure DevOps organization. /// </summary> /// <param name="bindingManager">Binding manager.</param> /// <param name="orgName">Organization name.</param> public static void SignOut(this IAzureReposBindingManager bindingManager, string orgName) { EnsureArgument.NotNullOrWhiteSpace(orgName, nameof(orgName)); // // Unbind the organization so we prompt the user to select a user on the next attempt. // // U = User // X = Do not inherit (valid in local only) // - = No user // // Global | Local | -> | Global | Local // --------|-------|----|--------|------- // - | - | -> | - | - // - | U | -> | - | - // - | X | -> | - | - // U | - | -> | U | X // U | X | -> | U | X // U | U | -> | U | X // AzureReposBinding existingBinding = bindingManager.GetBinding(orgName); if (existingBinding is null) { // Nothing to do! } else if (existingBinding.GlobalUserName is null) { bindingManager.Unbind(orgName, local: true); } else { bindingManager.Bind(orgName, AzureReposBinding.NoInherit, local: true); } }
/// <summary> /// Marks a user as 'signed in' to an Azure DevOps organization. /// </summary> /// <param name="bindingManager">Binding manager.</param> /// <param name="orgName">Organization name.</param> /// <param name="userName">User identifier to bind to this organization.</param> public static void SignIn(this IAzureReposBindingManager bindingManager, string orgName, string userName) { EnsureArgument.NotNullOrWhiteSpace(orgName, nameof(orgName)); EnsureArgument.NotNullOrWhiteSpace(userName, nameof(userName)); // // Try to bind the user to the organization. // // A = User to sign-in // B = Another user // - = No user // // Global | Local | -> | Global | Local // --------|-------|----|--------|------- // - | - | -> | A | - // - | A | -> | A | - // - | B | -> | A | - // A | - | -> | A | - // A | A | -> | A | - // A | B | -> | A | - // B | - | -> | B | A // B | A | -> | B | A // B | B | -> | B | A // AzureReposBinding existingBinding = bindingManager.GetBinding(orgName); if (existingBinding?.GlobalUserName != null && !StringComparer.OrdinalIgnoreCase.Equals(existingBinding.GlobalUserName, userName)) { bindingManager.Bind(orgName, userName, local: true); } else { bindingManager.Bind(orgName, userName, local: false); bindingManager.Unbind(orgName, local: true); } }