typesense-swift icon indicating copy to clipboard operation
typesense-swift copied to clipboard

How are you supposed to obfuscate the key in the Swift client?

Open bnhoang2k opened this issue 1 year ago • 5 comments

In the README, you make a node, then use that node to create a config, then finally use that config to create a client. However, you can't even make the config without an apiKey; is there a way to get this key without embedding it in the source code?

It seems weird that you need the client to make an api key; but in order to make a client, you need an API key first!

Typesense Version: v1.0.0

bnhoang2k avatar Sep 20 '24 22:09 bnhoang2k

On Typesense Cloud, you can generate an API key in the UI to use in the client. When self-hosting, you want to use the bootstrap API key in the client or in curl requests, to generate subsequent keys.

jasonbosco avatar Sep 21 '24 00:09 jasonbosco

That was the thing I was afraid of. I was trying to find a way to not embed the bootstrap key (or any key for that matter) into the source code of my iOS application to create other keys. I wanted to hide it.

Is there really no way around this?

bnhoang2k avatar Sep 21 '24 01:09 bnhoang2k

You would run the Typesense server on a remote server, start it with the bootstrap API key of your choice on that server. Then on the server, use the bootstrap API key with curl and the /keys API endpoint and generate a search api key and only use that generated api key in your client libraries.

That way you’re not exposing the bootstrap api key on the client side.

jasonbosco avatar Sep 21 '24 02:09 jasonbosco

So what I'm hearing is make search api key, then embed that into my code? There's no way to hide it?

bnhoang2k avatar Sep 22 '24 00:09 bnhoang2k

For a mobile app, you want to have an API endpoint on your backend, with authenticates a user and then generates a short-lived restricted API key for that user and passes it to the app on login. That way the API key is not embedded inside your app, instead it's ephemeral and only stored in memory.

You can periodically rotate the key as needed in your backend, and invalidate the old one.

jasonbosco avatar Sep 23 '24 19:09 jasonbosco