API Security
SWAT APIs support two ways of authentication and managing access to your data.
- Basic authentication
- OAuth2
- Api key authentication
Different groups of APIs may utilize diverse authentication methods to enhance the experience for consumers.
Basic authentication
APIs beginning with /api/v2 and /api/v2/microservices necessitate basic authentication. SWAT support must establish usernames and passwords. The same authentication technique is employed for the Optimization API located at /api/v1/node_scheduler/.
Api key authentication
Api key authentication is used by Routing API, specifically /tdroute and /tdtable paths. Api key has to be requested from SWAT support.
Token based authentication
Consumers who wish to impersonate passengers or drivers via a client-based system can use token-based authentication. This method is more secure and utilizes an OAuth-like authentication system. Endpoints requiring this type of authentication begin with the /passenger/v1 path, while the logging API is accessible at /passenger/v1/sessions.
Failed login attempts
A deployment can lock out repeated failed logins. When it does, Basic authentication on /api/v2 and the password grant of the OAuth2 token endpoint count failed passwords per username and per client IP. After too many failures in a short window, further attempts are refused, even with the right password, until the lock ends. A locked request gets HTTP 429 Too Many Requests with a Retry-After header (seconds until the lock ends) and the body {"error": "too_many_login_attempts"}. A successful login resets the username's count.
If your integration retries on 401, stop retrying on 429 and wait at least Retry-After seconds; retrying a wrong password only extends the lock. The thresholds are set per deployment; ask SWAT support for the values that apply to you.
Refreshing OAuth2 tokens
A refresh_token grant on the token endpoint returns a new access token. If the access token behind the refresh token was revoked, the endpoint answers 400 with {"error": "invalid_grant"}; sign in again with the password grant. Depending on the deployment, a refresh can also issue a new refresh token (use the new one from then on) and refresh tokens can expire after a fixed time, which gives the same invalid_grant answer.