Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiKey parameter does not work for Authentication of API Calls #52

Open
TriggerAu opened this issue Sep 28, 2024 · 2 comments
Open

ApiKey parameter does not work for Authentication of API Calls #52

TriggerAu opened this issue Sep 28, 2024 · 2 comments

Comments

@TriggerAu
Copy link
Contributor

The OktaConfiguration object has two APIKey properties

  • ApiKey
  • ApiKeyPrefix

These values are used in the APIs to set a Header parameter of apiToken to be the value inside ApiKey.apiToken and ApiKeyPrefix is ignored. The documentation about APIKey authorization says the header shoudl be Authorization and it should be a prefix of SSWS followed by the auth token per https://github.com/okta/okta-powershell-cli/blob/main/openapi3/management.yaml#L16409

Pass the API token as the Authorization header value prefixed with SSWS: `Authorization: SSWS {API Token}`

The test case I am using is attempting is this after digging into the code to find the structure of the ApiKey is this:

$Configuration = Get-OktaConfiguration
$Configuration.BaseUrl = 'https://myorg.okta.com'
$Configuration.ApiKey = @{apitoken='myApiToken`}'
$Configuration.ApiKeyPrefix = "SSWS"
Invoke-OktaListUsers

Which returns this

Invoke-WebRequest: E:\OktaWork\okta-powershell-cli\src\Okta.PowerShell\Private\OktaApiClient.ps1:171
Line |
 171 |  …               $RawResponse = Invoke-WebRequest -Uri $UriBuilder.Uri `
     |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     |  {   "errorCode": "E0000005",   "errorSummary": "Invalid session",   "errorLink": "E0000005",   "errorId":
     | "oaeuQp-VKZ-SUyDE5-SJIiYUA",   "errorCauses": [] }

The source of this is that setting the ApiKey is not being passed in to the Authorization header


I did find the swapping in terminology between ApiToken and ApiKey to be a bit challenging so it could be that Im misreading what ApiKey and Prefix is, but the yaml appeasr to indicate the terms being used interchangably

@laura-rodriguez
Copy link
Collaborator

Thanks for reporting this issue, @TriggerAu!

We'll revisit our docs and make sure this is properly documented. In the meantime, you can also do the following:

$Configuration = Get-OktaConfiguration
$Configuration.BaseUrl = 'https://YOURORG.okta.com'
$Configuration.DefaultHeaders = @{authorization = 'SSWS <API_TOKEN>'}

Internal Ref: OKTA-813704

@TriggerAu
Copy link
Contributor Author

TriggerAu commented Oct 5, 2024

Thanks @laura-rodriguez , I did do that headers one too, but with there being an ApiKey property I figured Id go the extra yard and make that useful too. If that property is for some other ApiKey then be cool to know what its use case is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants