Skip to content

Commit 77db898

Browse files
feat(api) add CUSTOM case to AuthStrategy (#1428)
1 parent 567ac28 commit 77db898

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

aws-api/src/test/java/com/amplifyframework/api/aws/auth/AuthRuleRequestDecoratorTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ public void ownerArgumentNotAddedForNonOwnerBasedAuth() throws AmplifyException
202202
GraphQLRequest<Group> modifiedRequest = decorator.decorate(originalRequest, mode);
203203
assertNull(getOwnerField(modifiedRequest));
204204
}
205+
206+
// Custom auth with function provider does not add owner field.
207+
for (SubscriptionType subscriptionType : SubscriptionType.values()) {
208+
GraphQLRequest<CustomFunction> originalRequest = createRequest(CustomFunction.class, subscriptionType);
209+
GraphQLRequest<CustomFunction> modifiedRequest = decorator.decorate(originalRequest, mode);
210+
assertNull(getOwnerField(modifiedRequest));
211+
}
205212
}
206213

207214
/**
@@ -350,6 +357,9 @@ private abstract static class Public implements Model {}
350357
@ModelConfig(authRules = { @AuthRule(allow = AuthStrategy.PRIVATE) })
351358
private abstract static class Private implements Model {}
352359

360+
@ModelConfig(authRules = { @AuthRule(allow = AuthStrategy.CUSTOM, provider = "function") })
361+
private abstract static class CustomFunction implements Model {}
362+
353363
@ModelConfig(authRules = { @AuthRule(allow = AuthStrategy.OWNER) })
354364
private abstract static class Owner implements Model {}
355365

core/src/main/java/com/amplifyframework/core/model/AuthStrategy.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,35 @@
2525
* * documentation.</a>
2626
*/
2727
public enum AuthStrategy {
28+
/**
29+
* Custom authorization restricts access based on anything, as defined by the customer, such as via an AWS Lambda
30+
* serverless function. To use CUSTOM, the API must have the AWS_LAMBDA auth type configured.
31+
*/
32+
CUSTOM(Provider.FUNCTION, 1),
33+
2834
/**
2935
* Owner authorization specifies whether a user can access or operate against an object. To use OWNER, the API
3036
* must have Cognito User Pool configured.
3137
*/
32-
OWNER(Provider.USER_POOLS, 1),
38+
OWNER(Provider.USER_POOLS, 2),
3339

3440
/**
3541
* Group authorization specifies whether a group can access or operate against an object. To use GROUPS, the API
3642
* must have Cognito User Pool configured.
3743
*/
38-
GROUPS(Provider.USER_POOLS, 2),
44+
GROUPS(Provider.USER_POOLS, 3),
3945

4046
/**
4147
* The private authorization specifies that everyone will be allowed to access the API with a valid JWT token from
4248
* the configured Cognito User Pool. To use PRIVATE, the API must have Cognito User Pool configured.
4349
*/
44-
PRIVATE(Provider.USER_POOLS, 3),
50+
PRIVATE(Provider.USER_POOLS, 4),
4551

4652
/**
4753
* The public authorization specifies that everyone will be allowed to access the API, behind the scenes the API
4854
* will be protected with an API Key. To use PUBLIC, the API must have API Key configured.
4955
*/
50-
PUBLIC(Provider.API_KEY, 4);
56+
PUBLIC(Provider.API_KEY, 5);
5157

5258
private final Provider defaultAuthProvider;
5359
private final int priority;

0 commit comments

Comments
 (0)