Today several bots use this service. However, only the one (https://github.com/kozalosev/LocPlaceBot) implemented the registration procedure. Thus, we have one service in the database. And multiple consumers.
userservicedb=# select * from services;
id | name | type
----+-------------+--------------
1 | LocPlaceBot | telegram-bot
(1 row)
Moreover, when we start registration of additional services, I'm afraid we'll encounter a problem:
message GetUserRequest {
int64 id = 1;
bool by_external_id = 2;
}
- Our
Get message consists of only the ID. No service_id.
- the registration process tries to fetch or create a service, tries to find a user based on
service_id and external_id. If nothing found, it just creates a new user.
That is in practice, for 1 external_id we get 2 different user_ids.
Solution
- We should use the fact that
external_id is common for all telegram_bots, telegram_channels.
- Add a
token_hash column to the Services table. Generate a token on registration, save its hash into DB, and return in response. Add this as a mandatory parameter for get, update and activatePremium calls. Then user-service will be able to securely authenticate specific service and use this name to write audit logs, for example. Anyway, completely anonymous access should be discouraged. Note that consumers must use pgcrypto (pgp_sym_encrypt/pgp_sym_decrypt) or something alike if they store the token in the database as well.
- Simplify registration of additional services if the user already exists and accepted the consent. It must be executed automatically. If
get returns nothing, try first to call activate_service (new RPC call) which checks the user exists and create a new mapping automatically.
Today several bots use this service. However, only the one (https://github.com/kozalosev/LocPlaceBot) implemented the registration procedure. Thus, we have one service in the database. And multiple consumers.
Moreover, when we start registration of additional services, I'm afraid we'll encounter a problem:
Getmessage consists of only the ID. Noservice_id.service_idandexternal_id. If nothing found, it just creates a new user.That is in practice, for 1
external_idwe get 2 differentuser_ids.Solution
external_idis common for alltelegram_bots,telegram_channels.token_hashcolumn to theServicestable. Generate a token on registration, save its hash into DB, and return in response. Add this as a mandatory parameter forget,updateandactivatePremiumcalls. Thenuser-servicewill be able to securely authenticate specific service and use this name to write audit logs, for example. Anyway, completely anonymous access should be discouraged. Note that consumers must use pgcrypto (pgp_sym_encrypt/pgp_sym_decrypt) or something alike if they store the token in the database as well.getreturns nothing, try first to callactivate_service(new RPC call) which checks the user exists and create a new mapping automatically.