Issues with Generating Scope API Keys in Python
TLDR Danny had issues generating a valid scope API key in a Python GraphQL server. Jason suggested encoding changes and confirmed that the key length varies. Issue unresolved with Python, although JS library worked.
Jun 09, 2022 (17 months ago)
Danny
04:27 PMb'YVZidxxxxxxxx4MDk4fQ=='"
try deleting the weird fields like the b, the single quotes and the equals signs, but it still gives me an error.
I was guided by this documentation
https://typesense.org/docs/0.23.0/api/api-keys.html#generate-scoped-search-key
Jason
04:33 PMDanny
04:37 PMclass TypesenseService(TypeSenseBase):
def __init__(self):
super().__init__()
self.__search_api_key = TYPESENSE_ADMIN_API_KEY
def get_api_key_limited_by_configuration(self, configuration):
result = self.typesense_client.keys.generate_scoped_search_key(self.__search_api_key, configuration)
return result
Danny
04:38 PM{
"exclude_fields": "person",
"expires_at": expiration_date
}
Danny
04:45 PMclass TypeSenseBase(object):
typesense_client = None
def __init__(self):
self.typesense_client = typesense.Client({
'nodes': [{
'host': TYPESENSE_HOST,
'port': TYPESENSE_PORT,
'protocol': 'http'
}],
'api_key': TYPESENSE_ADMIN_API_KEY,
'connection_timeout_seconds': 2
})
Jason
04:48 PMJason
04:49 PMresult
and see what it shows you server-side?Danny
04:50 PMDanny
04:54 PMb'K0lNZnpzVDFnbHdFWjdBYy9LYmZVK293LzcwWlBBNklEYmU3OGcvRHlDTT1JdHB4eyJleGNsdWRlX2ZpZWxkcyI6ICJwZXJzb24iLCAiZXhwaXJlc19hdCI6IDE2NTQ4ODAwNTQuODUyNzk0fQ=='
Danny
04:55 PMDanny
04:56 PMDanny
05:45 PMb%27Y21rWnlsUE1tbGxMckRWV1ZmZGczeTVUNFRGcEROOFhBc05uQm5KOXFyUT1JdHB4eyJmaWx0ZXJfYnkiOiAiYWNjZXNzaWJsZVRvQ29tcGFueUlkczokMTIzMzMiLCAiZXhwaXJlc19hdCI6IDE2NTQ4ODI5MTMuMTQyMzE4fQ%3D%3D%27
and use this name
x-typesense-api-key
Jason
05:56 PMJason
06:05 PMDanny
06:13 PMJason
06:15 PMDanny
06:17 PMmessage: "Forbidden - a valid x-typesense-api-key header must be sent."
Danny
06:18 PMDanny
06:20 PMc1JGZGRVdmJMeDFSVzNKSytYUlZ4YU1SbnRMNXhMQzVSRlZQajBzaVViOD1JdHB4eyJleGNsdWRlX2ZpZWxkcyI6ICJwZXJzb24iLCAiZXhwaXJlc19hdCI6IDE2NTQ4ODQ4MTEuNzgxMjMxfQ==
Jason
06:24 PMresult.decode('utf-8')
?Jason
06:24 PMDanny
06:35 PMDanny
06:36 PMJason
06:48 PMDanny
06:51 PMDanny
06:52 PMa09YSmRHZHcrVWl2eXA3clVCTWtLbVZvdnpCTEJUcHFSWXdhWTRMMFkwcz1JdHB4eyJleGNsdWRlX2ZpZWxkcyI6InBlcnNvbiIsImV4cGlyZXNfYXQiOjE2NTQ4ODU1NDJ9
but I still have the same error
Jason
06:54 PMJason
06:55 PMDanny
06:56 PMJason
07:00 PMParent key does not allow queries against queried collection. Key prefix: Itpx
Jason
07:01 PMScoped API keys can only be used for searches.
Danny
07:06 PMJason
07:09 PMDanny
07:14 PMJason
07:17 PMDanny
07:22 PMJason
07:22 PMDanny
07:22 PM[ "*" ]
Danny
07:23 PMJason
07:27 PMYou can rotate the API Keys you share with me once we finish debugging.
Danny
07:27 PMJason
07:59 PMCC: Kishore Nallan
Typesense
Indexed 2776 threads (79% resolved)
Similar Threads
Resolving Issues with Scoped API Keys in Typesense with Golang
Suvarna had problems with generating and using scoped API keys in Typesense with Golang. Several bugs misleading the user were found and fixed by Kishore Nallan.
Correct API Key Generation and Usage on Cloud
Tom faced 401 errors while creating keys via the Cloud API. Kishore Nallan clarified the correct syntax and mechanics, and identified a header mislabeling on Tom's part that caused the issue. They also discussed using scoped API keys.
Trouble with Scoped Search API Keys in Flutter App
Shane struggled with scoped search API keys in Typesense library for a Flutter app, which returned a 401 error. Jason identified that the error may be a result of an invalid filter within the key, and instructed to create separate keys for different permissions. On implementation, the error was resolved.
Issue with API Key Expiry and Generation in Node.js
Sai is having trouble with API keys expiring and triggering a forbidden key error in Node.js. Despite trying to generate a new key after expiry, Sai gets the same error. Jason explains that the problem may be due to the expiration of parent API keys.
Resolving Typesense Server Connection with Correct API Keys and Paths
Rubai had trouble creating a working API key for Typesense and understanding number_hits versus num_documents. Jason provided clarification and correct code for generating a search-only API Key and using correct server configurations.