Public/Connect-Dune.ps1
|
<# .SYNOPSIS Authenticate to the Dune API for a given tenant. .DESCRIPTION Establishes an authenticated Dune session using one of three authentication modes: interactive/social login (default), credential (username/password), or bearer token. Sets up session state used by other Dune cmdlets. .PARAMETER Tenant The tenant name or identifier to authenticate against. This parameter is required. .PARAMETER DuneInstance The target Dune instance to use. Valid values: Prod, Dev, Test, Local. Defaults to Prod. .PARAMETER Credential A PSCredential object used for credential-based authentication. Required when using the Credential parameter set. .PARAMETER BearerToken An OAuth bearer token string used for token-based authentication. Required when using the BearerToken parameter set. .EXAMPLE PS> Connect-Dune -Tenant "contoso" Uses the default social/interactive login flow for tenant contoso. .EXAMPLE PS> $cred = Get-Credential PS> Connect-Dune -Tenant "contoso" -Credential $cred -DuneInstance Dev Authenticates to the Dev instance using the supplied credential (Credential parameter set). .EXAMPLE PS> Connect-Dune -Tenant "contoso" -BearerToken "eyJhbGciOi..." Authenticates using a bearer token (BearerToken parameter set). #> function Connect-Dune { [CmdletBinding(DefaultParameterSetName='SocialLogin')] param( [Parameter(Mandatory)] [string]$Tenant, [Parameter()] [ValidateSet("Prod", "Dev","Test","Local")] [string]$DuneInstance = "Prod", [Parameter(ParameterSetName="Credential")] [PSCredential]$Credential, [Parameter(ParameterSetName="BearerToken")] [string]$BearerToken ) begin {} process { $DefaultApiAuthParams = @{ DuneInstance = $DuneInstance Tenant = $Tenant.toLower() } switch ($PSCmdlet.ParameterSetName) { "SocialLogin" { if ($AuthUrl) {} Invoke-DuneApiAuthSocial @DefaultApiAuthParams } "Credential" { Invoke-DuneApiAuthCredential @DefaultApiAuthParams -Credential $Credential } "BearerToken" { Invoke-DuneApiAuthBearer @DefaultApiAuthParams -BearerToken $BearerToken } } } end {} } |