0

我正在尝试将apollo-clientcommercetools集成,但没有获取令牌和令牌类型详细信息,下面是示例代码。

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

4

2 回答 2

1

要获取匿名会话的访问令牌,OAuth 客户端需要 create_anonymous_token 范围。您用于发送此请求的 API 客户端是否具有此范围?

您可以创建的匿名令牌的数量没有限制。

于 2021-03-16T14:11:00.167 回答
-1

查看您的错误,我可以简单地确定问题如下。

在测试您的代码时,您已经使用了创建匿名令牌的允许阈值。

现在,您要么等待一段时间,可能在第二天,要么您可以寻求支持。

于 2021-03-16T13:50:04.900 回答