API key as object.
Cixo Develop 於 6 月之前 修改了此頁面

API key as object.

When API key had been in the database, it is stored as string. But when it is processing, then it is representing as object. API key as object is instance of cx_apikey.apikey. That is read only object, with all properties of the API key, that mean:

  • prefix - Static prefix for all API keys.
  • prefix_separator - Separator between prefix and random part of the key.
  • content, key - Full API key as string.
  • size - Lenght of the full API key.

How to store API key in the database, or send it in request?

You can just convert it to string or use one from content or key property.

apikey = cx_apikey.apikey_generator("test").set_size(64).generate()
second_apikey = cx_apikey.apikey_generator("test").set_size(64).generate()

as_string = str(apikey)
as_string = apikey.content
as_string = apikey.key

How to compare two API keys?

You can just compare it as string, but when it is apikey object, also just use compare function.

result = apikey.compare(second_apikey)
result = apikey == second_apikey # Compare with __eq__ function
result = str(apikey) == str(second_apikey)