gpt4 book ai didi

azure - 未经授权,输入的授权 token 无法满足请求

转载 作者:行者123 更新时间:2023-12-03 03:06:03 24 4
gpt4 key购买 nike

我正在尝试使用资源 token 获取 documentdbclient。我有一个 Redis 集群,其中键作为用户身份,值作为资源 token 。我有一项服务,它使用主 key 为用户生成资源 token 并在 Redis 中更新它们。我正在使用以下代码在我的主服务中创建资源 token

  ResourceResponse<Permission> readPermissions = documentClient.readPermission("/dbs/customerdb/users/mobileuser/permissions/readperm", null);
String accessToken=permission.getToken();
DocumentClient documentClient = new DocumentClient(HOST, MASTER_KEY,
ConnectionPolicy.GetDefault(), ConsistencyLevel.Session);

然后我使用下面的代码来获取资源 token 并将其存储在redis中

jedis.put("Client_1",readPermissions .getResource().getToken());

现在,在客户端,当我尝试使用资源 token 创建 documentClient

DocumentClient manageClient = new DocumentClient(HOST,  jedis.get("Client_1"),ConnectionPolicy.GetDefault(), ConsistencyLevel.Session);

我收到日志,指出未经授权,并出现错误

Unauthorized, The input authorization token can't serve the request

我在数据库 customerdb 上创建了一个名为 mobileuser 的用户,并使用模式 PermissionMode.Read 对集合客户创建了权限

我更改了代码,以确保 token 没有过期,但仍然出现错误

  java.lang.IllegalStateException: com.microsoft.azure.documentdb.DocumentClientException: The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'get

科尔斯dxhxakm3caa=2017 年 6 月 5 日星期一 08:56:40 GMT

下面是我用来获取 token 的代码

    ResourceResponse<Permission> permissions=documentClient.readPermission("/dbs/customerdd/users/mobileuser/permissions/readperm", null);
System.out.println(permissions.getResource().getResourceLink());
DocumentClient managedClient=new DocumentClient(HOST,permissions.getResource().getToken(), ConnectionPolicy.GetDefault(), ConsistencyLevel.Session);
FeedResponse<Document> response = managedClient.queryDocuments(collection.getResource().getSelfLink(), "SELECT customers.source FROM customers where customers.source='direct-mail'", null);
Iterator<Document> itr = response.getQueryIterator();
while(itr.hasNext()){
Document doc=itr.next();
System.out.println(doc.get("source"));
}

任何指针都会有很大帮助

最佳答案

Unauthorized, The input authorization token can't serve the request

据我所知,默认有效时间跨度为the resource token是一小时。并且如果资源 token 过期,后续请求会收到401未授权异常,请在从Redis缓存中检索资源 token 时确保资源 token 是否过期。

更新:

If i use the overloaded constructor of DocumentClient and pass the PermissionFeed then it works

DocumentClient class有如下两个构造函数,当您使用 new DocumentClient(HOST, jedis.get("Client_1"),ConnectionPolicy.GetDefault(), ConsistencyLevel.Session); 时,它似乎识别 jedis.get("Client_1") 您作为字符串传递并使用第二个构造函数来初始化新实例,这将是问题的原因。

enter image description here

关于azure - 未经授权,输入的授权 token 无法满足请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44353016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com