Skip to content

Add apiKeys.validateApiKey method#1373

Merged
nholden merged 1 commit intomainfrom
feature/auth-5388-add-validate-api-key-to-node-sdk
Oct 28, 2025
Merged

Add apiKeys.validateApiKey method#1373
nholden merged 1 commit intomainfrom
feature/auth-5388-add-validate-api-key-to-node-sdk

Conversation

@nholden
Copy link
Member

@nholden nholden commented Oct 28, 2025

Description

We're introducing API keys to help developers provide secure authentication to their APIs. This PR exposes the validate API key endpoint, which is currently under development and looks like this:

Validate API key

POST /api_keys/validations

Parameters

  • value: The value for an API key

Returns

  • api_key: api_key | null

Here's what a call to this new method might look like in a developer's application:

workos.apiKeys.validateApiKey({ value })
// { apiKey: { ... } } or { apiKey: null }

Documentation

This will require a docs change, which will come in a future PR.

@nholden nholden self-assigned this Oct 28, 2025
@nholden nholden requested a review from a team as a code owner October 28, 2025 00:24
@nholden nholden requested a review from rwtombaugh October 28, 2025 00:24
@linear
Copy link

linear bot commented Oct 28, 2025

@nholden nholden requested review from mthadley and nicknisi and removed request for rwtombaugh October 28, 2025 00:25
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

Added new apiKeys.validateApiKey method to the SDK that exposes WorkOS's API key validation endpoint. The implementation follows established patterns in the codebase.

  • New ApiKeys class with validateApiKey method that sends POST requests to /api_keys/validations
  • Proper serialization/deserialization for snake_case API responses to camelCase SDK format
  • Handles both valid API key responses and null (invalid) responses correctly
  • Comprehensive test coverage for valid and invalid key scenarios
  • No security issues detected - API key values are only sent in the request payload, not logged
  • Consistent with existing SDK patterns for error handling and type definitions

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Clean implementation following established SDK patterns with comprehensive test coverage and no security concerns
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/api-keys/api-keys.ts 5/5 New ApiKeys class with validateApiKey method for API key validation endpoint
src/api-keys/api-keys.spec.ts 5/5 Comprehensive tests for valid and invalid API key scenarios
src/api-keys/interfaces/validate-api-key.interface.ts 5/5 Request and response interfaces for API key validation, handles null responses correctly
src/workos.ts 5/5 Added apiKeys instance to main WorkOS class

Sequence Diagram

sequenceDiagram
    participant App as Developer Application
    participant SDK as WorkOS SDK
    participant API as WorkOS API
    
    App->>SDK: workos.apiKeys.validateApiKey({ value })
    SDK->>SDK: Serialize request payload
    SDK->>API: POST /api_keys/validations
    Note over SDK,API: Payload: { value: "sk_..." }
    API->>API: Validate API key
    alt Valid API Key
        API-->>SDK: { api_key: { id, owner, permissions, ... } }
        SDK->>SDK: Deserialize response
        SDK-->>App: { apiKey: ApiKey }
    else Invalid API Key
        API-->>SDK: { api_key: null }
        SDK->>SDK: Deserialize response
        SDK-->>App: { apiKey: null }
    end
Loading

8 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@nholden nholden merged commit ef588f1 into main Oct 28, 2025
5 checks passed
@nholden nholden deleted the feature/auth-5388-add-validate-api-key-to-node-sdk branch October 28, 2025 00:44
@nholden nholden mentioned this pull request Oct 28, 2025
nholden added a commit that referenced this pull request Oct 28, 2025
Version bump that includes:

- #1372
- #1373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants