我有一个使用 IAM 身份验证的 AppSync 应用程序(连接到 Cognito 用户和身份池)。使用 IAM 身份验证时,$event.context.identity 是一个 Cognito 身份池对象,没有用户信息(没有用户名、子、电子邮件等)
我相信每当我发出 graphQL 请求时,我都需要将 UserPoolID JWT(可通过 Amplify 在客户端使用)传递给 AppSync。但我一直无法弄清楚如何将 JWT 添加到(大概)标题中。
-------------EDIT------------- AppSyncClient 是客户端(基于 apollo 构建)。App.js 看起来像
import React from 'react';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import appSyncConfig from "./AppSync";
import { ApolloProvider } from "react-apollo";
import AWSAppSyncClient from "aws-appsync";
import { Rehydrated } from "aws-appsync-react";
import { Auth } from 'aws-amplify'
import AWS from'aws-sdk';
import AllPosts from './Components/AllPosts';
// more routes
const Home = () => (
<div > <AllPosts /> </div>
);
const App = () => (
<div> <Router> <div>
<Route exact={true} path="/" component={Home} />
//more routes
</div> </Router> </div>
);
const client = new AWSAppSyncClient({
url: appSyncConfig.graphqlEndpoint,
region: appSyncConfig.region,
auth: {
type: appSyncConfig.authenticationType, //AWS_IAM
apiKey: appSyncConfig.apiKey,
credentials: () => Auth.currentCredentials(),
});
const WithProvider = () => (
<ApolloProvider client={client}>
<Rehydrated>
<App />
</Rehydrated>
</ApolloProvider>
);
export default WithProvider;