Private/Get-DuneJWTTokens.ps1
|
<#
.SYNOPSIS Exchange a temporary token for JWT access and refresh tokens. .DESCRIPTION Posts the temporary token to the Dune auth endpoint and returns the JWT token pair (access token and refresh token) for the specified tenant. .PARAMETER DuneInstance The target Dune instance. Valid values: Prod, Dev, Test, Local. .PARAMETER Tenant The tenant name to authenticate against. .PARAMETER TemporaryToken The temporary token received from the social login callback. .EXAMPLE PS> Get-DuneJWTTokens -DuneInstance Prod -Tenant "yendico" -TemporaryToken "abc123" Exchanges the temporary token for JWT tokens. #> function Get-DuneJWTTokens { [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateSet("Prod", "Dev","Test","Local")] [string]$DuneInstance, [Parameter(Mandatory)] [string]$Tenant, [Parameter(Mandatory)] [string]$TemporaryToken ) $DuneApiUrl = Get-DuneApiUrl -DuneInstance $DuneInstance $AuthUrl = "{0}{1}" -f $DuneApiUrl, "/auth/temptoken" $Headers = @{ "Accept" = "application/json" "Content-Type" = "application/json" "X-Tenant" = $Tenant } Write-Debug "$($MyInvocation.MyCommand)|process|Getting new session ..." $Response = Invoke-WebRequest -Uri $AuthUrl -Method POST -Headers $Headers -Body (@{accesstoken = $TemporaryToken} | ConvertTo-Json) -UseBasicParsing $ResponseContent = $Response.content | ConvertFrom-Json return $ResponseContent } |