Implementing authentication
Here, we will leverage the PAT approach as it is more convenient and can work even in environments where no web browser can be launched, such as CI/CD pipelines.
To illustrate how this could be achieved, we will need to implement functionalities at two levels:
- BookmarkrSyncr: The external service will receive the PAT, validate it, and authenticate the user if it is valid
- Bookmarkr: The responsibility of the CLI application is to pass the token to the external service and act according to the response it gets from the sent request
Let’s start by adding the required functionality into BookmarkrSyncr.
Authenticating external services using a PAT
To make things simple, we will assume that BookmarkrSyncr (the code for which can be found in the AppendixB
folder) holds two PAT tokens: a valid one and an expired one. All other values that the user passes will be considered invalid and will be rejected for this reason.
The token...