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
+5 -18
View File
@@ -61,26 +61,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(),
@@ -89,6 +74,8 @@ let client = Client(
)
```
The `BearerAuthMiddleware` automatically injects the `Authorization` header with the Bearer token into every outgoing request.
## Supported Platforms
- iOS 13.0+