如何在客户端查询中添加HMAC



我们在我们的React Native项目中使用了Apolloclient,任何人都可以指导我们如何在使用它进行查询中添加HMAC?

我希望这有帮助

import ApolloClient, { gql } from 'apollo-boost';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { print } from 'graphql/language/printer';
const baseURL = 'http://localhost:3000/';
const cache = new InMemoryCache({
    addTypename: false
});
const apolloClient = new ApolloClient({
    uri: baseURL,
    cache,
    request: (operation) => {
        const { query, variables, operationName } = operation;
        const payload = {
            variables,
            operationName,
            query: print(query)
        }
        console.log(payload)
        // custom headers
        const headers = {
            'X-API-KEY': '332dace0-e629-48bf-b664-d550ebfc828c',
            'X-APP-ID': '52557818-b027-43a8-bf45-fb87f98cd96e',
            'content-type': 'application/xjson',
            'Authorization': token ? `Bearer ${token}` : '',
        }
        console.log(headers)
        const token = ''; // create HMAC here
        operation.setContext({
            headers: {
                ...headers,
            }
        })
    }
});

相关内容

  • 没有找到相关文章

最新更新