Skip to content

Fix the storage and API #24

Description

@kozalosev

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;
}
  1. Our Get message consists of only the ID. No service_id.
  2. 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

  1. We should use the fact that external_id is common for all telegram_bots, telegram_channels.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions