When calling user-api-key/new with a client_id that is already used by another user the forum will throw a RecordNotUnique error and silently fail on an internal server error.
This might want to fail with something less silent informing the user that there already exists an API key with that client ID.
Though that brings me on the second question, are User API keys supposed to behave like that? Is the client ID supposed to be unique between all users?
Thank you for reporting this, I have a couple of questions though in order to help me look into this.
Can you provide a basic repro for this so that I can debug this locally? What is your use case for user-api-keys? Are you using the discourse hub mobile app or something else?
The first and repeating authorization will succeed as the first user, when using it again for another user without changing the client_id it will fail.
User API keys are used for allowing the user to use their forum account in the game client, so theyâll be able to post from ingame. We also have lot of users using them to authenticate with forum accounts to their own websites.
Whereas the client ID should be unique for the game clients, so each client is listed as seperate client in the apps screen. For website usecase youâd want to have one client ID so not each login is listed separately.
How should that be implemented for use cases where a website doesnât have its own authentication system for users and shouldnât be creating multiple user API applications?
If the application authenticating users should be used on multiple computers and does not have any user data prior to authentication, that is impossible.
I dont understand how this relates to the OP since that describes a case where a client ID is shared by multiple users where your case seems to describe where a user has multiple client ids.
Itâs called a client id and not user id because a user can have multiple clients!
In most standards like OAuth the client id is described as âapp identifierâ and can be used for all users (not just one), for example your forum social logins always use the same client id.
However since user API keys seem to be designed primarily for clients such as Discourse apps they might have been designed to be unique, it would be nice to know whether they are.
Answering the above would make it clear whether thereâs a check missing in user_api_keys.rb or a wrong index on the database. Because currently those requests currently throw a scary 500 error and show up in our /logs endpoint.