Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom-graph-signatures #743

Merged
merged 8 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/media/api_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,23 @@ Amplify.configure({
});
```

### Signing a GraphQL request to authenticate with AWS Identity Access Management (IAM).

Amplify provides the ability to sign requests for IAM authentication.

Add the following to your configuration statement to enable this for GraphQL requests that are processed through AWS API Gateway:

```js
Amplify.configure({
API: {
graphql_endpoint: 'https://www.example.com/my-graphql-endpoint',
graphql_endpoint_iam_region: 'my_graphql_apigateway_region'
}
});
```

Example region value: "us-east-1".

### Configuration for AWS AppSync

AWS AppSync is a cloud-based fully-managed GraphQL service that is integrated with AWS Amplify API category and command line tools with AWS Mobile CLI.
Expand Down
13 changes: 8 additions & 5 deletions packages/aws-amplify/src/API/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ export default class APIClass {
return this._api.endpoint(apiName);
}

private async _headerBasedAuth() {
private async _headerBasedAuth(defaultAuthenticationType?) {
const {
aws_appsync_authenticationType: authenticationType,
aws_appsync_authenticationType: authenticationType = defaultAuthenticationType,
aws_appsync_apiKey: apiKey,
} = this._options;
let headers = {};
Expand Down Expand Up @@ -334,14 +334,17 @@ export default class APIClass {
aws_appsync_graphqlEndpoint: appSyncGraphqlEndpoint,
graphql_headers = () => ({}),
graphql_endpoint: customGraphqlEndpoint,
graphql_endpoint_iam_region: customEndpointRegion
} = this._options;

const doc = parse(queryStr);
const query = print(doc);

const headers = {
...(!customGraphqlEndpoint && await this._headerBasedAuth()),
...(customGraphqlEndpoint && { Authorization: null }),
...(customGraphqlEndpoint &&
( customEndpointRegion ? await this._headerBasedAuth('AWS_IAM') : { Authorization: null } )
),
... await graphql_headers({ query: doc, variables })
};

Expand All @@ -354,8 +357,8 @@ export default class APIClass {
headers,
body,
signerServiceInfo: {
service: 'appsync',
region,
service: !customGraphqlEndpoint ? 'appsync' : 'execute-api',
region: !customGraphqlEndpoint ? region : customEndpointRegion
}
};

Expand Down