Problem Statement
I have tried multiple authentication methos within my Microservice with mixed results.
-
For Subscriptions I can get it to work with Auth in the header (base64 encoded)
requests.post(subscription_url, json=subscription_data, headers=headers)
-
For Tokens I can get it to work with Auth directly (basic username, password)
requests.post(token_url, json=token_data, auth=(username, password))
-
For Quering the database I can only get it to work with my personal credentials in the header (base64 encoded), 403 with C8Y ENV credentials
response = requests.get(url=f"{BASE_URL}/inventory/managedObjects/{id}", headers={"Accept": "application/json","Content-Type": "application/json","Authorization": f"Basic [personal Base64 Credentials]"})
Outcome
I am after:
- a clear guidance to centralize the auth methods
- an understanding of the auth architecture and process for microservices
- links to relevant documentation that clearly states the required auth method for:
- Subscription
- Token
- Standard DB Query
Example Code:
Ideal Auth Method:
tenant = os.getenv('C8Y_TENANT')
user = os.getenv('C8Y_USER')
password = os.getenv('C8Y_PASSWORD')
BASE_URL = "http://cumulocity:8111"
username = f"{tenant}/{user}"
credentials = f"{username}:{password}"
encoded_credentials = base64.b64encode(credentials.encode()).decode()
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": f"Basic {encoded_credentials}",
}
Subscription (Pass)
response = requests.post(subscription_url, json=subscription_data, headers=headers)
Token (Pass)
response = requests.post(token_url, json=token_data, auth=(username, password))
Managed Object
Auth in Header Personal Credentials (Pass)
response = requests.get(url=f"{BASE_URL}/inventory/managedObjects/{id}", headers={"Accept": "application/json","Content-Type": "application/json","Authorization": f"Basic [personal Base64 Credentials]"})
Auth in Header (Fail)
response = requests.get(url=f"{BASE_URL}/inventory/managedObjects/{id}", headers={"Accept": "application/json","Content-Type": "application/json","Authorization": f"Basic encoded_credentials"})
Response (info URL provided is not valid)
{
"error": "security/Forbidden",
"message": "Access is denied",
"info": "https://www.cumulocity.com/guides/reference/rest-implementation//#a-name-error-reporting-a-error-reporting"
}
Auth Directly (Fail)
response = requests.get(url=f"{BASE_URL}/inventory/managedObjects/{id}",auth=(username, password))
Response (info URL provided is not valid)
{
"error": "security/Forbidden",
"message": "Access is denied",
"info": "https://www.cumulocity.com/guides/reference/rest-implementation//#a-name-error-reporting-a-error-reporting"
}