v2025/src/PSSailpoint.V2025/Model/CreatePersonalAccessTokenRequest.ps1

#
# Identity Security Cloud V2025 API
# Use these APIs to interact with the Identity Security Cloud platform to achieve repeatable, automated processes with greater scalability. We encourage you to join the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss to connect with other developers using our APIs.
# Version: v2025
# Generated by OpenAPI Generator: https://openapi-generator.tech
#

<#
.SYNOPSIS

No summary available.

.DESCRIPTION

Object for specifying the name of a personal access token to create

.PARAMETER Name
The name of the personal access token (PAT) to be created. Cannot be the same as another PAT owned by the user for whom this PAT is being created.
.PARAMETER Scope
Scopes of the personal access token. If no scope is specified, the token will be created with the default scope ""sp:scopes:all"". This means the personal access token will have all the rights of the owner who created it.
.PARAMETER AccessTokenValiditySeconds
Number of seconds an access token is valid when generated using this Personal Access Token. If no value is specified, the token will be created with the default value of 43200.
.PARAMETER ExpirationDate
Date and time, down to the millisecond, when this personal access token will expire. **Important:** When `expirationDate` is `null` or empty (not included in the request body), the token will never expire. **Required Validation:** If `expirationDate` is `null` or empty, `userAwareTokenNeverExpires` must be set to `true`. This is a required validation rule. **Valid Values (dependent on `userAwareTokenNeverExpires`):** * **When `userAwareTokenNeverExpires` is `true` (or required to be `true`):** `expirationDate` can be `null` or omitted from the request body. When `expirationDate` is `null` or empty, the token will never expire. * **When `userAwareTokenNeverExpires` is `false` or omitted:** `expirationDate` must be provided and must be a valid date-time string representing a future date (after the current date/time). There is no upper limit on how far in the future the expiration date can be set. `expirationDate` cannot be `null` in this case. **Validation Rules:** * **If `expirationDate` is `null` or not included in the request body:** `userAwareTokenNeverExpires` must be set to `true` (required). The token will never expire. * **If `expirationDate` is provided and is not `null`:** `userAwareTokenNeverExpires` can be omitted.
.PARAMETER UserAwareTokenNeverExpires
Indicates that the user creating this Personal Access Token is aware of and acknowledges the security implications of creating a token that will never expire. When set to `true`, this flag confirms that the user understands the security risks associated with non-expiring tokens. **Security Awareness:** Setting this field to `true` serves as an explicit acknowledgment that the user creating the token understands: * Tokens that never expire pose a greater security risk if compromised * Non-expiring tokens should be used only when necessary and with appropriate security measures * Regular rotation and monitoring of non-expiring tokens is recommended **Required Validation:** If `expirationDate` is `null` or empty (not included in the request body), `userAwareTokenNeverExpires` must be set to `true`. This is a required validation rule. **Validation Rules:** * **If `expirationDate` is `null` or not included in the request body:** `userAwareTokenNeverExpires` must be set to `true` (required). * **If `expirationDate` is provided and is not `null`:** `userAwareTokenNeverExpires` can be omitted. **Behavior:** * When set to `true`: Indicates that the user acknowledges they are creating a token that will never expire. When `expirationDate` is `null` or empty, the token will never expire. * When set to `false` or not specified (and `expirationDate` is provided): The token will follow normal expiration rules based on the `expirationDate` field and `accessTokenValiditySeconds` setting.
.OUTPUTS

CreatePersonalAccessTokenRequest<PSCustomObject>
#>


function Initialize-V2025CreatePersonalAccessTokenRequest {
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${Name},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String[]]
        ${Scope},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [System.Nullable[Int32]]
        ${AccessTokenValiditySeconds},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [System.Nullable[System.DateTime]]
        ${ExpirationDate},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [System.Nullable[Boolean]]
        ${UserAwareTokenNeverExpires} = $false
    )

    Process {
        'Creating PSCustomObject: PSSailpoint.V2025 => V2025CreatePersonalAccessTokenRequest' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        if (!$Name) {
            throw "invalid value for 'Name', 'Name' cannot be null."
        }

        if ($AccessTokenValiditySeconds -and $AccessTokenValiditySeconds -gt 43200) {
          throw "invalid value for 'AccessTokenValiditySeconds', must be smaller than or equal to 43200."
        }

        if ($AccessTokenValiditySeconds -and $AccessTokenValiditySeconds -lt 15) {
          throw "invalid value for 'AccessTokenValiditySeconds', must be greater than or equal to 15."
        }


        $PSO = [PSCustomObject]@{
            "name" = ${Name}
            "scope" = ${Scope}
            "accessTokenValiditySeconds" = ${AccessTokenValiditySeconds}
            "expirationDate" = ${ExpirationDate}
            "userAwareTokenNeverExpires" = ${UserAwareTokenNeverExpires}
        }

        return $PSO
    }
}

<#
.SYNOPSIS

Convert from JSON to CreatePersonalAccessTokenRequest<PSCustomObject>

.DESCRIPTION

Convert from JSON to CreatePersonalAccessTokenRequest<PSCustomObject>

.PARAMETER Json

Json object

.OUTPUTS

CreatePersonalAccessTokenRequest<PSCustomObject>
#>

function ConvertFrom-V2025JsonToCreatePersonalAccessTokenRequest {
    Param(
        [AllowEmptyString()]
        [string]$Json
    )

    Process {
        'Converting JSON to PSCustomObject: PSSailpoint.V2025 => V2025CreatePersonalAccessTokenRequest' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        $JsonParameters = ConvertFrom-Json -InputObject $Json

        # check if Json contains properties not defined in V2025CreatePersonalAccessTokenRequest
        $AllProperties = ("name", "scope", "accessTokenValiditySeconds", "expirationDate", "userAwareTokenNeverExpires")
        foreach ($name in $JsonParameters.PsObject.Properties.Name) {
            if (!($AllProperties.Contains($name))) {
                throw "Error! JSON key '$name' not found in the properties: $($AllProperties)"
            }
        }

        If ([string]::IsNullOrEmpty($Json) -or $Json -eq "{}") { # empty json
            throw "Error! Empty JSON cannot be serialized due to the required property 'name' missing."
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "name"))) {
            throw "Error! JSON cannot be serialized due to the required property 'name' missing."
        } else {
            $Name = $JsonParameters.PSobject.Properties["name"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "scope"))) { #optional property not found
            $Scope = $null
        } else {
            $Scope = $JsonParameters.PSobject.Properties["scope"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "accessTokenValiditySeconds"))) { #optional property not found
            $AccessTokenValiditySeconds = $null
        } else {
            $AccessTokenValiditySeconds = $JsonParameters.PSobject.Properties["accessTokenValiditySeconds"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "expirationDate"))) { #optional property not found
            $ExpirationDate = $null
        } else {
            $ExpirationDate = $JsonParameters.PSobject.Properties["expirationDate"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "userAwareTokenNeverExpires"))) { #optional property not found
            $UserAwareTokenNeverExpires = $null
        } else {
            $UserAwareTokenNeverExpires = $JsonParameters.PSobject.Properties["userAwareTokenNeverExpires"].value
        }

        $PSO = [PSCustomObject]@{
            "name" = ${Name}
            "scope" = ${Scope}
            "accessTokenValiditySeconds" = ${AccessTokenValiditySeconds}
            "expirationDate" = ${ExpirationDate}
            "userAwareTokenNeverExpires" = ${UserAwareTokenNeverExpires}
        }

        return $PSO
    }

}