-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathAppSyncAuthorizer.swift
More file actions
56 lines (47 loc) · 1.92 KB
/
Copy pathAppSyncAuthorizer.swift
File metadata and controls
56 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
import AWSClientRuntime
import Foundation
import SmithyIdentity
/// An authorizer that provides credentials for a specific AppSync auth mode.
///
/// Each case encodes its auth mode and holds the provider needed to produce
/// authorization credentials for that mode.
public enum AppSyncAuthorizer: @unchecked Sendable {
/// API Key authorization.
/// - Parameter fetchApiKey: Async function that provides the API key.
case apiKey(_ fetchApiKey: @Sendable () async throws -> String)
/// Amazon Cognito User Pools authorization.
/// - Parameter fetchToken: Async function that returns a valid access/ID token.
case userPools(_ fetchToken: @Sendable () async throws -> String)
/// OpenID Connect authorization.
/// - Parameter fetchToken: Async function that returns a valid OIDC token.
case oidc(_ fetchToken: @Sendable () async throws -> String)
/// AWS Lambda custom authorization.
/// - Parameter fetchToken: Async function that returns a valid authorization token.
case lambda(_ fetchToken: @Sendable () async throws -> String)
/// IAM (SigV4) authorization.
/// - Parameter credentialIdentityResolver: Provides IAM credentials for SigV4 signing.
case iam(_ credentialIdentityResolver: any AWSCredentialIdentityResolver)
/// The auth mode this authorizer provides.
public var authMode: AppSyncAuthMode {
switch self {
case .apiKey: return .apiKey
case .userPools: return .userPools
case .oidc: return .oidc
case .lambda: return .lambda
case .iam: return .iam
}
}
}
// Convenience factory for static API key
public extension AppSyncAuthorizer {
/// Creates an API Key authorizer with a static key value.
static func apiKey(_ apiKey: String) -> AppSyncAuthorizer {
.apiKey { apiKey }
}
}