Skip to content

Commit ff756bb

Browse files
authored
feat: support for lambda authorizer (#1334)
* feat: lambda authorizer, update AuthRule and AuthRuleProvider * feat: add AWSLambdaAuth * feat: update AWSAuthorizationType docs * feat: update interceptors, renamed shared types * feat: update AWSAuthorizationConfiguration, fix warnings * chore: lambda auth unit tests * chore: update comments, remove unused associated value * chore: add tests * chore: add more interceptors tests * feat: update SyncEngine requirements * remove region from Lambda auth configuration * sync requirements, explicit provider switch case * style change * integration tests * integration tests * throw PluginError if token provider not available * resolve lint errors * AuthToken interceptor * update integ tests instructions * update integ tests instructions * update documentation * test paginated query * address PR comments * return public/custom if user not logged in
1 parent 872b695 commit ff756bb

File tree

35 files changed

+1086
-95
lines changed

35 files changed

+1086
-95
lines changed

Amplify.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
762C978526210F6400798FA3 /* RecordCover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 762C978426210F6400798FA3 /* RecordCover.swift */; };
249249
762C978E26210FF100798FA3 /* RecordCover+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 762C978D26210FF100798FA3 /* RecordCover+Schema.swift */; };
250250
762F70A426683EE2001F8252 /* AuthRuleExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 762F70A326683EE2001F8252 /* AuthRuleExtensionTests.swift */; };
251+
7638895326A7A9AC0061AF0B /* AWSLambdaAuthConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7638895226A7A9AC0061AF0B /* AWSLambdaAuthConfiguration.swift */; };
251252
7678B38426017D5300B4917F /* AppSyncErrorTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7678B38326017D5300B4917F /* AppSyncErrorTypeTests.swift */; };
252253
7678B38526017D5300B4917F /* AppSyncErrorTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7678B38326017D5300B4917F /* AppSyncErrorTypeTests.swift */; };
253254
767F85FC2649FF540076D633 /* CustomerOrder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 767F85FB2649FF540076D633 /* CustomerOrder.swift */; };
@@ -1141,6 +1142,7 @@
11411142
762C978426210F6400798FA3 /* RecordCover.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordCover.swift; sourceTree = "<group>"; };
11421143
762C978D26210FF100798FA3 /* RecordCover+Schema.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RecordCover+Schema.swift"; sourceTree = "<group>"; };
11431144
762F70A326683EE2001F8252 /* AuthRuleExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRuleExtensionTests.swift; sourceTree = "<group>"; };
1145+
7638895226A7A9AC0061AF0B /* AWSLambdaAuthConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AWSLambdaAuthConfiguration.swift; sourceTree = "<group>"; };
11441146
7678B38326017D5300B4917F /* AppSyncErrorTypeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSyncErrorTypeTests.swift; sourceTree = "<group>"; };
11451147
767F85FB2649FF540076D633 /* CustomerOrder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerOrder.swift; sourceTree = "<group>"; };
11461148
767F85FD2649FFCC0076D633 /* CustomerOrder+Schema.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CustomerOrder+Schema.swift"; sourceTree = "<group>"; };
@@ -1993,6 +1995,7 @@
19931995
21420A7C237222A700FA140C /* APIKeyConfiguration.swift */,
19941996
21420A7D237222A700FA140C /* AWSAuthorizationConfiguration.swift */,
19951997
21420A7B237222A700FA140C /* AWSIAMConfiguration.swift */,
1998+
7638895226A7A9AC0061AF0B /* AWSLambdaAuthConfiguration.swift */,
19961999
21420A7F237222A700FA140C /* CognitoUserPoolsConfiguration.swift */,
19972000
21420A7E237222A700FA140C /* OIDCConfiguration.swift */,
19982001
);
@@ -2972,8 +2975,6 @@
29722975
762167D42615435C0033FCD2 /* Record+Schema.swift */,
29732976
762C978426210F6400798FA3 /* RecordCover.swift */,
29742977
762C978D26210FF100798FA3 /* RecordCover+Schema.swift */,
2975-
6B7743D625906F7E001469F5 /* Restaurant */,
2976-
21A9051E2616442000EC141D /* Scalar */,
29772978
6B9F7C542526864800F1F71C /* ScenarioATest6Post.swift */,
29782979
6B9F7C532526864800F1F71C /* ScenarioATest6Post+Schema.swift */,
29792980
214F49742486D8A200DA616C /* User.swift */,
@@ -4748,6 +4749,7 @@
47484749
2129BE1E2394806B006363A1 /* QueryPredicate+GraphQL.swift in Sources */,
47494750
21420A8F237222A900FA140C /* AWSIAMConfiguration.swift in Sources */,
47504751
219A888523EB897700BBC5F2 /* GraphQLRequest+AnyModelWithSync.swift in Sources */,
4752+
7638895326A7A9AC0061AF0B /* AWSLambdaAuthConfiguration.swift in Sources */,
47514753
219A88F123F3379900BBC5F2 /* GraphQLDocumentInput.swift in Sources */,
47524754
21AD424E249BF0E90016FE95 /* AnyModel+Subscript.swift in Sources */,
47534755
21420AA0237222A900FA140C /* AWSAuthorizationType.swift in Sources */,

Amplify/Categories/API/AuthProvider/APIAuthProviderFactory.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ open class APIAuthProviderFactory {
1818
open func oidcAuthProvider() -> AmplifyOIDCAuthProvider? {
1919
return nil
2020
}
21+
22+
open func functionAuthProvider() -> AmplifyFunctionAuthProvider? {
23+
return nil
24+
}
25+
}
26+
27+
public protocol AmplifyAuthTokenProvider {
28+
typealias AuthToken = String
29+
func getLatestAuthToken() -> Result<AuthToken, Error>
2130
}
2231

2332
/// Amplify OIDC Auth Provider
24-
public protocol AmplifyOIDCAuthProvider {
33+
public protocol AmplifyOIDCAuthProvider: AmplifyAuthTokenProvider {}
2534

26-
/// Retrieve the latest auth token
27-
func getLatestAuthToken() -> Result<String, Error>
28-
}
35+
/// Amplify Function Auth Provider
36+
public protocol AmplifyFunctionAuthProvider: AmplifyAuthTokenProvider {}

Amplify/Categories/DataStore/Model/Internal/Schema/AuthRule.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public enum AuthStrategy {
1212
case groups
1313
case `private`
1414
case `public`
15+
case custom
1516
}
1617

1718
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
@@ -30,6 +31,7 @@ public enum AuthRuleProvider {
3031
case oidc
3132
case iam
3233
case userPools
34+
case function
3335
}
3436

3537
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly

Amplify/Categories/DataStore/Subscribe/MutationEvent+Model.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension MutationEvent {
2020
mutationType: mutationType,
2121
version: version)
2222
}
23-
23+
2424
public init(untypedModel model: Model,
2525
modelName: ModelName,
2626
mutationType: MutationType,

0 commit comments

Comments
 (0)