我正在尝试将apollo-client与commercetools集成,但没有获取令牌和令牌类型详细信息,下面是示例代码。
import ApolloClient from 'apollo-client';
import { createHttpLink } from 'apollo-link-http';
import { setContext } from 'apollo-link-context';
import { InMemoryCache } from 'apollo-cache-inmemory';
import SdkAuth, { TokenProvider } from '@commercetools/sdk-auth';
// Create token provider for the commercetools project
const tokenProvider = new TokenProvider({
sdkAuth: new SdkAuth({
host: 'https://auth.us-central1.gcp.commercetools.com/',
projectKey: 'test-ecommerce-store',
credentials: {
clientId: '<clinet_id>',
clientSecret: '<clientSecret>',
},
scopes: ['manage_products:test-ecommerce-store'],
}),
fetchTokenInfo: sdkAuth => sdkAuth.anonymousFlow(),
});
const httpLink = createHttpLink({
uri: 'https://api.us-central1.gcp.commercetools.com/test-ecommerce-store/graphql',
});
const authLink = setContext((_, { headers = {} }) => tokenProvider.getTokenInfo()
.then(tokenInfo => `${tokenInfo.token_type} ${tokenInfo.access_token}`)
.then(authorization => ({ headers: { ...headers, authorization } })));
export default new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache()
});
错误:“invalid_scope” error_description:“权限超出:获取匿名令牌所需的 create_anonymous_token 权限。” 错误:[{code: "invalid_scope",…}] 消息:“权限超出:获取匿名令牌所需的 create_anonymous_token 权限。” 状态码:400