Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API Keys Support #16

Open
natterstefan opened this issue Sep 16, 2022 · 5 comments
Open

Add API Keys Support #16

natterstefan opened this issue Sep 16, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@natterstefan
Copy link

natterstefan commented Sep 16, 2022

Hi @Dean151,

once again, thank you for creating a replacement for the deprecated and now offline API for our pet feeder devices. I'm playing with your API, and I can't wait to see the final Deployment section in the README to set this up in my local network.

Until then, I've another feature request that's gonna be helpful when using the API with Smart Home Buttons like the AWS IoT Button and others: API Keys.

Feature Request

  • add endpoint which allows creating API keys
  • add endpoint which allows deleting API keys
  • API keys can be used to use the feeders/{id}/feed and feeders/{id}/planning endpoint

I ask for API keys as I am unsure how long the authentication token is valid without me updating IoT button requests again and again.

Thank you very much!

@Dean151
Copy link
Owner

Dean151 commented Sep 16, 2022

Seems like a reasonable ask.
API keys are way less secure than renewable jwt (and I don't even know myself how many time they're stay valid either) ; but my pick would be less than 24h.
I'll also add an option to customize this token validity threshold.

@Dean151 Dean151 self-assigned this Sep 16, 2022
@Dean151 Dean151 added the enhancement New feature or request label Sep 16, 2022
@Dean151
Copy link
Owner

Dean151 commented Sep 16, 2022

Just for the sake of it, your IoT button can trigger any script?
If so, you can also create a password to your account, and then use that password to authenticate ; then trigger the meal in your script ; and wire that to the IoT button.
I'm proposing that because usually the good practice for API keys is that they are to be used to authenticate and obtain an expirable token to be used then for the real thing.

@natterstefan
Copy link
Author

natterstefan commented Sep 16, 2022

I'll also add an option to customize this token validity threshold.

Thank you, I can't wait to see how one can deploy your solution in the own home network.

Just for the sake of it, your IoT button can trigger any script?

Good questions. It has been a while since I set up the button. But I quickly checked and yes it triggers a lambda function on AWS which runs node. So technically, I could do some more requests than just the one triggering the feed endpoint.

I'm proposing that because usually the good practice for API keys is that they are to be used to authenticate and obtain an expirable token to be used then for the real thing.

Yeah, you are right. Makes sense.

So this is the sequence of requests, correct?

POST user/reset (create password)
POST user/reset/consume (get a token)
POST POST feeders/{id}/feed

And I need to do this every time I hit the button because the token expires. 👍

Question though: what's the difference for you compared to API keys in that regard? I need a key (email+password) to obtain one that expires to get to the result I want. My code still needs to know the secrets (email+pw in this case). It's the expiration factor, isn't it? 🤔

@Dean151
Copy link
Owner

Dean151 commented Sep 17, 2022

I would say that the process would be two step:

  1. Manually create a password
POST user/reset (ask for a one time login token)
POST user/reset/consume (consume one time login token ; provide an authorization token for next steps)
GET user/me (get your user id)
PUT user/<id> (update your password)
  1. In your script (with password)
POST user/login (get an authorization token using email/password)
POST feeder/<id>/feed (trigger a meal)

Later, with the API token it'll be something like:

POST user/token/consume (use API token to get authorization token)
POST feeder/<id>/feed (trigger a meal)

@natterstefan
Copy link
Author

Hi @Dean151,

just for the record, I want to confirm that steps 1 and 2 work flawlessly for my use case but require a server/serverless endpoint available somewhere. It's not a big deal with Vercel, for instance, though.

@Dean151 Dean151 removed their assignment Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants