| 1 | # Store GitHub OAuth credentials in dotnet user-secrets for IntercomService (survives publish-debug /MIR). |
| 2 | # Usage: |
| 3 | # .\scripts\intercom\set-intercom-github-user-secrets.ps1 -ClientId "<id>" -ClientSecret "<secret>" |
| 4 | # .\scripts\intercom\set-intercom-github-user-secrets.ps1 -FromLocalFile # migrate appsettings.Development.local.json once |
| 5 | [CmdletBinding()] |
| 6 | param( |
| 7 | [string] $ClientId = "", |
| 8 | [string] $ClientSecret = "", |
| 9 | [switch] $FromLocalFile |
| 10 | ) |
| 11 | |
| 12 | $ErrorActionPreference = "Stop" |
| 13 | $repoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\..")) |
| 14 | $proj = Join-Path $repoRoot "host\intercom-service\src\IntercomService\IntercomService.csproj" |
| 15 | if (-not (Test-Path -LiteralPath $proj)) { |
| 16 | Write-Error "IntercomService.csproj not found: $proj" |
| 17 | exit 1 |
| 18 | } |
| 19 | |
| 20 | if ($FromLocalFile) { |
| 21 | $local = Join-Path $repoRoot "host\intercom-service\src\IntercomService\appsettings.Development.local.json" |
| 22 | if (-not (Test-Path -LiteralPath $local)) { |
| 23 | Write-Error "No appsettings.Development.local.json at $local" |
| 24 | exit 1 |
| 25 | } |
| 26 | $json = Get-Content -LiteralPath $local -Raw | ConvertFrom-Json |
| 27 | $ClientId = $json.GitHub.ClientId |
| 28 | $ClientSecret = $json.GitHub.ClientSecret |
| 29 | } |
| 30 | |
| 31 | if ([string]::IsNullOrWhiteSpace($ClientId) -or [string]::IsNullOrWhiteSpace($ClientSecret)) { |
| 32 | Write-Error "Provide -ClientId and -ClientSecret, or -FromLocalFile." |
| 33 | exit 1 |
| 34 | } |
| 35 | |
| 36 | dotnet user-secrets set "GitHub:ClientId" $ClientId.Trim() --project $proj |
| 37 | dotnet user-secrets set "GitHub:ClientSecret" $ClientSecret.Trim() --project $proj |
| 38 | Write-Host "OK: GitHub OAuth in user-secrets (UserSecretsId 7f3c8a2e-4b1d-4f9a-9c2e-1a8b4d6e0f31)." |
| 39 | Write-Host "Path: $env:APPDATA\Microsoft\UserSecrets\7f3c8a2e-4b1d-4f9a-9c2e-1a8b4d6e0f31\secrets.json" |
| 40 | Write-Host "Works for dotnet run and published IntercomService.exe when ASPNETCORE_ENVIRONMENT=Development." |
| 41 | |