<# S'authentifie et ecrit le jeton dans jwt.txt (non versionne). #> param( [Parameter(Mandatory=$true)][string]$Email, [string]$Password, [string]$BaseUrl = "http://localhost:5000" ) $ErrorActionPreference = "Stop" . "$PSScriptRoot\_common.ps1" if ([string]::IsNullOrWhiteSpace($Password)) { $Password = Read-PlainPassword "Mot de passe" } try { $auth = Invoke-RestMethod -Method Post -Uri "$BaseUrl/api/Authentication/Authenticate" ` -ContentType "application/json" ` -Body (@{ email = $Email.ToLower(); password = $Password } | ConvertTo-Json) } catch { Write-Host " ECHEC : $(Get-HttpErrorBody $_)" -ForegroundColor Red Write-Host " 'Object reference not set' = l'instance du compte n'existe pas en base" -ForegroundColor Yellow Write-Host " (TokensService.cs:82 lit .PinCode sans test de nullite)." -ForegroundColor Yellow exit 1 } $jwt = $auth.access_token if (-not $jwt) { Write-Host "Reponse inattendue :"; $auth | ConvertTo-Json -Depth 4; exit 1 } Write-Utf8NoBom "$PSScriptRoot\jwt.txt" $jwt # JsonStringEnumConverter (Startup.cs) serialise les enums en chaine : role vaut # "SuperAdmin", pas 0. On accepte les deux formes. $role = "$($auth.role)" Write-Host " Jeton ecrit dans jwt.txt ($($jwt.Length) caracteres)" -ForegroundColor Green if ($role -eq "SuperAdmin" -or $role -eq "0") { Write-Host " Role : $role -- MigrationController acceptera." -ForegroundColor Green } else { Write-Host " Role : $role -- il faut SuperAdmin pour migrer." -ForegroundColor Red }