Authentication
Logging into cobra APIs with Bearer Tokens: A Quick Guide
Introduction
Securing access to our cobra APIs is paramount, and one effective method for authentication is through the use of Bearer Tokens. Bearer Tokens are a type of access token that provides a simple and secure way to authenticate requests to our APIs. This brief guide will walk you through the process of logging into Cobra APIs using Bearer Tokens.
Getting Started
Obtain API Credentials: Before diving into authentication, ensure you have the necessary API user credentials, including an email and api key, which will be used to obtain the Bearer Token.
Generate Bearer Token: Use the client credentials grant flow to exchange your email and api key for a Bearer Token. Make a request to the token endpoint with the following parameters:
POST /auth/token { "username": "your@email.de", "password": "your_api_key" }
The response will include an access token that you'll use as the Bearer Token.
Include Bearer Token in Requests: With the Bearer Token in hand, include it in the Authorization header of your API requests:
Authorization: Bearer your_access_token
Replace your_access_token with the actual Bearer Token obtained in step 2.
Best Practices
Secure Storage: Safeguard your client credentials and tokens. Avoid hardcoding them in your source code, and use secure methods for storage.
Token Expiry Handling: Be prepared to handle token expiration gracefully by implementing token refreshing as needed. Token lifetime is one hour.
HTTPS Usage: Always use HTTPS when interacting with cobra APIs to secure the transmission of credentials and tokens.