Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/checkout-4
Browse files Browse the repository at this point in the history
  • Loading branch information
goagain authored Nov 14, 2023
2 parents 840e1b0 + f81ad81 commit 9030b51
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 40 deletions.
54 changes: 36 additions & 18 deletions .github/workflows/azure-devops-pipelines-cg.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# This pipeline will be triggered when either main branch is pushed or 2AM on workdays.
variables:
- name: tags
value: "production"
readonly: true
trigger:
branches:
include:
Expand All @@ -9,21 +13,35 @@ schedules:
branches:
include:
- main

jobs:
- job: ComponentGovernance
displayName: Component Governance
pool:
name: Azure Pipelines
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
- task: DotNetCoreCLI@2
displayName: dotnet restore
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
resources:
repositories:
- repository: CustomPipelineTemplates
type: git
name: 1ESPipelineTemplates/OfficePipelineTemplates
ref: refs/tags/release
extends:
template: v1/Office.Official.PipelineTemplate.yml@CustomPipelineTemplates
parameters:
pool:
name: Azure-Pipelines-1ESPT-ExDShared
image: windows-2022
os: windows
customBuildTags:
- ES365AIMigrationTooling
stages:
- stage: __default
jobs:
- job: ComponentGovernance
displayName: Component Governance
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
- task: DotNetCoreCLI@2
displayName: dotnet restore
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.8.4] - 2023-09-05
### Changed
- Upgrade Lasso to `2023.8.24.1`.
- Upgrade MSAL to `4.55.0`.

## [0.8.3] - 2023-08-24
### Added
- Added support for distributing debian packages.
Expand Down Expand Up @@ -171,7 +176,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial project release.

[Unreleased]: https://github.com/AzureAD/microsoft-authentication-cli/compare/0.8.3...HEAD
[Unreleased]: https://github.com/AzureAD/microsoft-authentication-cli/compare/0.8.4...HEAD
[0.8.4]: https://github.com/AzureAD/microsoft-authentication-cli/compare/0.8.3...0.8.4
[0.8.3]: https://github.com/AzureAD/microsoft-authentication-cli/compare/0.8.2...0.8.3
[0.8.2]: https://github.com/AzureAD/microsoft-authentication-cli/compare/0.8.1...0.8.2
[0.8.1]: https://github.com/AzureAD/microsoft-authentication-cli/compare/0.8.0...0.8.1
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Microsoft Authentication CLI

[![Tests](https://img.shields.io/github/actions/workflow/status/AzureAd/microsoft-authentication-cli/.github/workflows/dotnet-test.yml?branch=main&style=for-the-badge&logo=github)](https://github.com/AzureAD/microsoft-authentication-cli/actions/workflows/dotnet-test.yml)
[![Release](https://img.shields.io/badge/Release-0.8.3-orange?style=for-the-badge&logo=github)](https://github.com/AzureAD/microsoft-authentication-cli/releases/tag/0.8.3)
![GitHub release (latest by SemVer)](https://img.shields.io/github/downloads/azuread/microsoft-authentication-cli/0.8.3/total?logo=github&style=for-the-badge&color=blue)
[![Release](https://img.shields.io/badge/Release-0.8.4-orange?style=for-the-badge&logo=github)](https://github.com/AzureAD/microsoft-authentication-cli/releases/tag/0.8.4)
![GitHub release (latest by SemVer)](https://img.shields.io/github/downloads/azuread/microsoft-authentication-cli/0.8.4/total?logo=github&style=for-the-badge&color=blue)
[![License](https://shields.io/badge/license-MIT-purple?style=for-the-badge)](./LICENSE.txt)

---
Expand Down Expand Up @@ -34,8 +34,8 @@ provide a means of downloading the latest release, so you **must** specify your
To install the application, run

```powershell
# 0.8.3 is an example. See https://github.com/AzureAD/microsoft-authentication-cli/releases for the latest.
$env:AZUREAUTH_VERSION = '0.8.3'
# 0.8.4 is an example. See https://github.com/AzureAD/microsoft-authentication-cli/releases for the latest.
$env:AZUREAUTH_VERSION = '0.8.4'
$script = "${env:TEMP}\install.ps1"
$url = "https://raw.githubusercontent.com/AzureAD/microsoft-authentication-cli/${env:AZUREAUTH_VERSION}/install/install.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Expand All @@ -45,6 +45,8 @@ Invoke-WebRequest $url -OutFile $script; if ($?) { &$script }; if ($?) { rm $scr
**Note**: The script does not signal currently running processes to update their environments, so you'll need to
relaunch applications before the `$PATH` changes take effect.

**Note**: Uninstalling can be done with the uninstallation script. [Read more](docs/uninstall.md)

## macOS

On macOS we provide a shell bootstrap script, which will download and extract the application to `$HOME/.azureauth`
Expand All @@ -55,8 +57,8 @@ release, so you **must** specify your desired version via the `$AZUREAUTH_VERSIO
To install the application, run

```bash
# 0.8.3 is an example. See https://github.com/AzureAD/microsoft-authentication-cli/releases for the latest.
export AZUREAUTH_VERSION='0.8.3'
# 0.8.4 is an example. See https://github.com/AzureAD/microsoft-authentication-cli/releases for the latest.
export AZUREAUTH_VERSION='0.8.4'
curl -sL https://raw.githubusercontent.com/AzureAD/microsoft-authentication-cli/$AZUREAUTH_VERSION/install/install.sh | sh
```

Expand Down
2 changes: 1 addition & 1 deletion bin/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ oauthlib==3.2.2
requests==2.31.0
requests-oauthlib==1.3.1
six==1.16.0
urllib3==1.26.12
urllib3==1.26.18
16 changes: 16 additions & 0 deletions docs/uninstall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Uninstalling AzureAuth

The uninstall script can be used to uninstall AzureAuth (currently only available for Windows). The script removes the default AzureAuth reference in the PATH and deletes the AzureAuth installation folder.

The script currently doesn't support uninstalling from custom locations. This is to avoid removing any potential files that are not safe to delete. If there are any potential installations in custom locations found in the PATH (installed through the `$AZUREAUTH_INSTALL_DIRECTORY` environment variable), a warning will be printed showing its location. Installations in custom locations that are not listed in the PATH cannot be found and uninstalled.

## Usage

Run the following in PowerShell:

```PowerShell
$script = "${env:TEMP}\uninstall.ps1"
$url = "https://raw.githubusercontent.com/AzureAD/microsoft-authentication-cli/main/install/uninstall.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest $url -OutFile $script; if ($?) { &$script }; if ($?) { rm $script }
```
23 changes: 9 additions & 14 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,15 @@ release_name() {
case "${os_name}" in
Darwin)
name="${name}-osx"
arch="$(echo $os_info | rev | cut -d ' ' -f1 | rev)"

case "${arch}" in
arm64)
name="${name}-arm64"
;;
x86_64)
name="${name}-x64"
;;
*)
error "Unsupported architecture '${arch}', unable to download a release"
exit 1
;;
esac
# check if os_info contains arm64 or x86_64
if echo $os_info | grep -q arm64; then
name="${name}-arm64"
elif echo $os_info | grep -q x86_64; then
name="${name}-x64"
else
error "Unsupported architecture '${arch}', unable to download a release"
exit 1
fi
;;
*)
error "Unsupported OS '${os_name}', unable to download a release"
Expand Down
132 changes: 132 additions & 0 deletions install/uninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Enable a default -Verbose flag for debug output.
[CmdletBinding()]
$VerbosePreference = "Continue"

# Halt script execution at the first failed command.
$script:ErrorActionPreference='Stop'

$azureauthDefaultLocation = ([System.IO.Path]::Combine($Env:LOCALAPPDATA, "Programs", "AzureAuth"))

function Get-CustomLocationsFromPath {
$customLocations = [System.Collections.ArrayList]@()
$azureauthsInPath = (Get-Command -Name azureauth -ErrorAction SilentlyContinue -CommandType Application -All).Source

ForEach($az in $azureauthsInPath) {
$azureauthParent = (Get-Item $az).Directory.FullName
if (!(Is-ChildOfDefaultLocation($azureauthParent))) {
$_ = $customLocations.Add($azureauthParent)
}
}

return $customLocations
}

function Write-WarningForCustomLocations {
# We only warn the user of any custom locations that are found in the PATH.
# Installations in custom locations that are not listed in PATH cannot
# be found and uninstalled.
$customLocations = Get-CustomLocationsFromPath
$customLocationsCount = $customLocations.Count

if ($customLocationsCount -ne 0) {
$warning = "Uninstallation from custom locations is unsupported. Custom locations must be removed manually.
`rFound ${customLocationsCount} potential installations outside of the default location:"
ForEach($location in $customLocations) {
$warning += "`n ${location}"
}
Write-Warning $warning
}
}

# Send WM_SETTINGCHANGE after changing Environment variables.
# Refer to https://gist.github.com/alphp/78fffb6d69e5bb863c76bbfc767effda
function Send-SettingChange {
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
"@
$HWND_BROADCAST = [IntPtr] 0xffff;
$WM_SETTINGCHANGE = 0x1a;
$result = [UIntPtr]::Zero

[void] ([Win32.Nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [UIntPtr]::Zero, "Environment", 2, 5000, [ref] $result))
}

function Is-ChildOfDefaultLocation {
param ([string]$path)

$parent = (Split-Path $path -Parent)
return ($parent -eq $azureauthDefaultLocation)
}

function Remove-FromPath {
$registryPath = 'Registry::HKEY_CURRENT_USER\Environment'
$currentPath = (Get-ItemProperty -Path $registryPath -Name PATH -ErrorAction SilentlyContinue).Path

# Reconstruct the $PATH without any azureauth directories.
$updatedPath = "";
if (($null) -ne $currentPath) {
$paths = $currentPath.Split(";")
$pathArr = @()
ForEach($path in $paths){
if(!$path.Equals("") -And !(Is-ChildOfDefaultLocation($path))) {
$pathArr += "${path}"
}
elseif (!$path.Equals("")) {
Write-Verbose "Removing PATH entry '${path}'"
}
}
$updatedPath = ($pathArr -join ";") + ";"
}

Set-ItemProperty -Path $registryPath -Name PATH -Value $updatedPath
Send-SettingChange
}

function Remove-InstallationFolder {
param ([string]$directory)

if (Test-Path -Path $directory) {
Write-Verbose "Removing all installations at '${directory}'"
Remove-Item -Force -Recurse $directory
} else {
Write-Verbose "There were no installations found at '${directory}'"
}
}

function Remove-Directories {
Remove-InstallationFolder $azureauthDefaultLocation
}

function Kill-Process {
# Uninstall will fail if there are instances of AzureAuth running.
# We suppress taskkill output here because this is a best effort attempt and we don't want the user to see its output.
# Here, Get-Process is used to first determine whether there is an existing azureauth process. If there is, kill the existing process first.
$ProcessCheck = Get-Process -Name azureauth -ErrorAction SilentlyContinue -ErrorVariable ProcessError
if ($null -ne $ProcessCheck) {
Write-Verbose "Stopping any currently running azureauth instances"
taskkill /f /im azureauth.exe 2>&1 | Out-Null

# After killing the process it is still possible for there there to be locks on the files it was using (including
# its own DLLs). The OS may take an indeterminate amount of time to clean those up, but so far we've observed 1
# second to be enough.
Start-Sleep -Seconds 1
}
}

function Uninstall {
if (![string]::IsNullOrEmpty($Env:AZUREAUTH_INSTALL_DIRECTORY) `
-And $Env:AZUREAUTH_INSTALL_DIRECTORY -ne $azureauthDefaultLocation) {
Write-Warning "Ignoring AZUREAUTH_INSTALL_DIRECTORY environment variable. Uninstallation for custom locations is not supported."
}

Kill-Process

Remove-Directories
Remove-FromPath

Write-WarningForCustomLocations
Write-Output "Uninstalled AzureAuth!"
}

Uninstall

0 comments on commit 9030b51

Please sign in to comment.