Generate the API Keys Feature

The API Keys feature provides two things:

  1. It provides users of your service with the ability to manage their own API Key records in the Session Store
  2. It extends the authorization middleware to look for Authorization: Bearer <an-api-key> authorization headers and to look them up in the Session Store

Generate the API Keys feature like this:

$ saas-rs generate feature --name api-keys --service user --version 1

The following content is added or changed in your Rust workspace:

crates/
├── session_store/
│   ├── src/
│   │   └── bucket.rs
└── user_server/
│   └── src/
│       └── v1/
│           ├── controllers/
│           │   ├── api_key.rs
│           │   └── mod.rs
│           ├── middleware/
│           │   └── authorization.rs
│           └── mod.rs
proto/
└── acme/
    └── user/
        └── v1/
            ├── api_key.proto
            ├── api_key_resource.proto
            └── user_service.proto

And the following things occurred:

  • a Session Store bucket enum variant was added for storing API Key records
  • an API Key controller was generated with a full Session Store backed implementation
  • the authorizaton middleware was rewritten and augmented with API Key record lookups in the Session Store when an Authorization: Bearer ... header is present in inbound gRPC http requests
  • Protobuf files were generated for the API Key model and its associated resource, which supports your end users self-service managing their API Keys

A Fork based graphical diff view does the best job of showing the changes that were made in the authorization middleware module:

Diff view of authorization middleware module


©2025 SaaS RS | Website | GitHub | GitLab | Contact