【发布时间】:2017-06-04 10:22:08
【问题描述】:
我正在尝试使用资源令牌获取 documentdbclient。我有一个 redis 集群,其中键作为用户身份,值作为资源令牌。 我有一个使用主密钥为用户生成资源令牌并在 Redis 中更新它们的服务。我正在使用以下代码在我的主服务中创建资源令牌
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);
然后我使用下面的代码来获取resourcetoken并将其存储在redis中
jedis.put("Client_1",readPermissions .getResource().getToken());
现在,当我尝试使用资源令牌创建 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 模式创建了权限
我更改了我的代码以确保令牌没有过期但仍然出现错误
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
下面是我用来获取令牌的代码
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"));
}
任何指针都会有很大帮助
【问题讨论】:
-
"readPermissions .getResource().getToken()"- 我希望引号只是问题中的拼写错误? -
是的,这些是错别字...我已经编辑了它们。谢谢指出
标签: azure azure-cosmosdb