Command: Subscribe
The subscribe command let’s you subscribe to a tunnel and receive webhook requests locally.
Currently the subscribe
command is the most important one in the Corbado CLI. It lets you subscribe to our tunnel server to receive webhook requests locally.
To fully understand the subscribe
command you should get familiar with our webhooks first.
Problem with local development
Before we start with explaining the command itself let’s talk about a problem with local development and the reason why we created the subscribe
command.
Corbado sends webhook requests to your application. On production this is no problem: your webhook is exposed on the internet (with proper authentication) and Corbado can send webhook requests.
Locally this is not that easy. Let’s say you implement your webhook backend with PHP (any other language / technology works as well) and run a local development server:
php -S localhost:8000
Now your application listens on localhost port 8000. You can access your webhook locally but Corbado has no way to access your local running application to send webhook requests.
Solution
To solve this problem we created the subscribe
command which opens a tunnel from your local computer to Corbado. This tunnel is then used to exchange webhook requests and responses.
See the following chart how webhook requests and responses flow through the system:
Command execution
You implemented your webhook in PHP (any other language / technology works as well) and can access it locally via http://localhost:8000/corbadoWebhookHandler.php
(this is your webhooks URL).
The command execution looks like the following:
corbado subscribe http://localhost:8000
In the CLI subscribe
command, provide only http://localhost:8000, not the full URL!
We did not provide any authentication information, see authentication methods
Next you need to configure the webhooks URL in the developer panel. Here you must set the full URL to http://localhost:8000/corbadoWebhookHandler.php.
Done: now you can test the full authentication journey!
Technical details
Underneath we use websockets (do not get confused with webhooks) to exchange webhook requests and responses.
The subscribe
command opens a websocket connection to our tunnel server which itself actually is a websocket server. We use the websocket connection to “tunnel” webhook requests and responses.