Skip to content

Conversation

@aniket-okta
Copy link
Contributor

@aniket-okta aniket-okta commented Nov 3, 2025

Summary

Fixes API token authentication that was completely broken, causing all requests with -ApiKey parameter to fail with 403 "Invalid session" errors. This fix resolves multiple reported issues affecting customers who were completely blocked from using API token authentication.

Issues Fixed

Closes #91
Closes #86
Closes #52

Problem

Customers using Set-OktaConfiguration -ApiKey @{apitoken = "..."} were unable to authenticate to Okta API. The authentication header was never being added to API requests, causing all calls to fail with 403 errors.

Root Cause: In OktaApiClient.ps1 (lines 82-85), the code created a local $headers variable with the Authorization header but never merged it into $HeaderParameters, which is what actually gets sent with the HTTP request.

Solution

  • Fixed authentication header injection by directly assigning to $HeaderParameters["Authorization"]
  • Added default "SSWS" prefix for Okta API tokens
  • Added type-safe handling for ApiKeyPrefix configuration
  • Added explicit check for apitoken key existence
  • Maintains backward compatibility with DefaultHeaders workaround

Changes

Modified:

  • src/Okta.PowerShell/Private/OktaApiClient.ps1 - Fixed ApiKey authentication logic (11 lines)
  • README.md - Updated documentation to remove outdated warnings and promote ApiKey as recommended approach (34 lines)
  • .github/CODEOWNERS - Added @manmohan-shaw-okta as codeowner

Added:

  • tests/Integration/ApiKeyAuth.Integration.Tests.ps1 - Integration test coverage for ApiKey authentication (48 lines)

Testing

  • All 442 existing tests still pass
  • New integration tests validate ApiKey configuration and authentication
  • Manually verified: Get-OktaUser -UserId 'me' successfully authenticates with API token
  • Backward compatibility confirmed with DefaultHeaders workaround
  • No regressions introduced

Impact

Before: API token authentication completely non-functional - customers blocked
After: API token authentication works as documented

Related PRs

This PR supersedes:

Credits

Co-authored-by: @TriggerAu

@aniket-okta aniket-okta self-assigned this Nov 3, 2025
@aniket-okta aniket-okta force-pushed the fix/apikey-authentication-403 branch from f9ba17d to c10f86a Compare November 3, 2025 10:56
BinoyOza-okta
BinoyOza-okta previously approved these changes Nov 3, 2025
aniket-okta and others added 2 commits November 3, 2025 16:39
Fixes API token authentication that was broken due to Authorization header
never being added to HTTP requests. The $headers variable was created but
never merged into $HeaderParameters.

Changes:
- Updated api_client.mustache template to add Authorization header
- Fixed OktaApiClient.ps1 (generated from template)
- Added integration tests for ApiKey authentication

Closes #91
Closes #86
Closes #52

Co-authored-by: TriggerAu <TriggerAu@users.noreply.github.com>
@aniket-okta aniket-okta merged commit e6d6807 into main Nov 4, 2025
6 checks passed
@aniket-okta aniket-okta deleted the fix/apikey-authentication-403 branch November 4, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants