Skip to content

APIKey is not passed to the OktaAPIClient #91

@TriggerAu

Description

@TriggerAu

In this block of code the APIKey and Prefix are used to eset a varioable called $headers, but that variable is not used after that as part of the send to Invoke-WebRequest

if ($Configuration.ApiKey -and $Configuration.ApiKeyPrefix) {
$headers = @{
Authorization = "$($Configuration.ApiKeyPrefix) $($Configuration.ApiKey.apitoken)"
}
}

This means that this part of the documentation fails as it never passes an Authorization header

The ApiKey property contains the API token, and ApiKeyPrefix should be used to prefix the token when setting the Authorization header.
The OktaConfiguration object includes two important properties for API authentication:
ApiKey: This should contain the actual API token in the form of a hashtable, e.g., @{ apitoken = '<yourApiToken>' }.
ApiKeyPrefix: This is an optional prefix (default: "SSWS") to be used before the API token when setting the Authorization header.
Example Usage:
```powershell
$Configuration = Get-OktaConfiguration
$Configuration.BaseUrl = 'https://your-org.okta.com'
$Configuration.ApiKey = @{ apitoken = '<yourApiToken>' }
$Configuration.ApiKeyPrefix = "SSWS" # Optional, defaults to "SSWS"
```
The resulting HTTP header will be:
```powershell
Authorization: SSWS <yourApiToken>

The fix to this is to update the Authorization header inside the if statement so its passed on to the next call as below

    if ($Configuration.ApiKey -and $Configuration.ApiKeyPrefix) {
        $HeaderParameters["Authorization"] = "$($Configuration.ApiKeyPrefix) $($Configuration.ApiKey.apitoken)"
    }

Will raise a PR shortly including the Mustache fix for this - which will fix part of #90 as well

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions