Skip to content

Commit 51ae631

Browse files
authored
chore: add docs for defaultAuthMode (#8462)
1 parent 5f48718 commit 51ae631

File tree

2 files changed

+52
-0
lines changed
  • src
    • fragments/lib/restapi/js
    • pages/[platform]/build-a-backend/add-aws-services/rest-api/customize-authz

2 files changed

+52
-0
lines changed

src/fragments/lib/restapi/js/authz.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@ By default, the API will be using IAM authorization and the requests will be sig
66

77
When you created your REST API with the Amplify CLI, you were asked if you wanted to restrict access. If you selected **no**, then the unauthenticated role will have access to the API. If you selected **yes**, you would have configured more fine grain access to your API.
88

9+
For public REST APIs you can change the default behavior by using the `defaultAuthMode` attribute. You can change this per request:
10+
11+
```javascript
12+
await get({
13+
apiName: 'myApi',
14+
path: '/public-endpoint',
15+
options: {
16+
defaultAuthMode: 'none' // Skip default IAM authentication for this request
17+
}
18+
});
19+
````
20+
21+
or globally through `libraryOptions`:
22+
23+
```javascript
24+
Amplify.configure({
25+
// ... other config
26+
}, {
27+
API: {
28+
REST: {
29+
defaultAuthMode: 'none' // Default mode for all REST calls
30+
}
31+
}
32+
});
33+
```
34+
935
## API Key
1036

1137
If you want to configure a public REST API, you can set an API key in Amazon API Gateway. Then, you can set the API key header in the API category configuration. The API key header will be applied to all requests.

src/pages/[platform]/build-a-backend/add-aws-services/rest-api/customize-authz/index.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,32 @@ When determining the authorization mode for your REST endpoint, there are a few
3232

3333
By default, the API will be using IAM authorization and the requests will be signed for you automatically. IAM authorization has two modes: one using an **unauthenticated** role, and one using an **authenticated** role. When the user has not signed in, the unauthenticated role is used by default. Once the user has signed in, the authenticate role is used, instead.
3434

35+
For public REST APIs you can change the default behavior by using the `defaultAuthMode` attribute. You can change this per request:
36+
37+
```javascript
38+
await get({
39+
apiName: 'myApi',
40+
path: '/public-endpoint',
41+
options: {
42+
defaultAuthMode: 'none' // Skip default IAM authentication for this request
43+
}
44+
});
45+
````
46+
47+
or globally through `libraryOptions`:
48+
49+
```javascript
50+
Amplify.configure({
51+
// ... other config
52+
}, {
53+
API: {
54+
REST: {
55+
defaultAuthMode: 'none' // Default mode for all REST calls
56+
}
57+
}
58+
});
59+
```
60+
3561
## API Key
3662

3763
If you want to configure a public REST API, you can set an API key in Amazon API Gateway or create one using the [CDK construct](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ApiKey.html). Then, you can set the API key header in the API configuration which will be applied to all requests.

0 commit comments

Comments
 (0)