Implemented the BearerAuthMiddleware middleware in the library target.

This commit is contained in:
2026-03-26 00:30:02 +01:00
parent 99b202a34e
commit d1761e8a83
5 changed files with 234 additions and 36 deletions
@@ -59,26 +59,11 @@ The App Store Connect API requires authentication using API keys. You'll need to
1. Create an API key in App Store Connect
2. Generate a signed JWT token using your key ID, issuer ID, and private key
3. Inject the token into each request via an OpenAPI middleware
3. Pass the token to the built-in ``BearerAuthMiddleware`` when creating the client
```swift
import OpenAPIRuntime
struct BearerAuthMiddleware: ClientMiddleware {
let token: String
func intercept(
_ request: HTTPRequest,
body: HTTPBody?,
baseURL: URL,
operationID: String,
next: @Sendable (HTTPRequest, HTTPBody?, URL) async throws -> (HTTPResponse, HTTPBody?)
) async throws -> (HTTPResponse, HTTPBody?) {
var request = request
request.headerFields[.authorization] = "Bearer \(token)"
return try await next(request, body, baseURL)
}
}
import ASConnectService
import OpenAPIURLSession
let client = Client(
serverURL: try Servers.server1(),
@@ -87,6 +72,8 @@ let client = Client(
)
```
The ``BearerAuthMiddleware`` automatically injects the `Authorization` header with the Bearer token into every outgoing request.
## Supported Platforms
- iOS 13.0+
@@ -108,6 +95,10 @@ let client = Client(
- ``Client``: The main API client for making requests
### Authentication
- ``BearerAuthMiddleware``: A client middleware that injects a Bearer token into outgoing HTTP requests
### API Endpoints
The package provides access to all App Store Connect API endpoints including: