I试图将阿波罗-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权限。“错误:{代码:"invalid_scope",…} message:“权限超出:获取匿名令牌所需的create_anonymous_token权限”。statusCode: 400
发布于 2021-03-16 14:11:00
要获得匿名会话的访问令牌,OAuth客户端需要create_anonymous_token作用域。用于发送此请求的API客户端是否具有此范围?
您可以创建的匿名令牌的数量没有限制。
发布于 2021-03-16 13:50:04
通过查看您的错误,我可以简单地确定问题如下。
在测试代码时,您已经消耗了创建匿名令牌的允许阈值。
现在,您可以等待一段时间,可能是第二天,或者您可以请求支持。
https://stackoverflow.com/questions/66655820
复制相似问题