It depends on the specific implementation of the JSON-RPC API you're using. Here's a breakdown of the two common scenarios:
1. Session-based Authentication:
- In this case, a successful authenticate call establishes a session on the server. This session is identified by a key or token (often not the user ID itself).
- Subsequent object calls typically require including this session key or token in the request header or as a parameter.
- This session has an expiration time. You don't need to call authenticate again until the session expires.
2. Token-based Authentication:
- Here, authenticate might return a JSON Web Token (JWT) or a similar token containing user information and claims.
- Subsequent object calls would require including this token in the request header (usually as an "Authorization" header).
- JWTs are self-contained and expire after a set time. You need to re-authenticate (get a new token) before the current one expires.
How to determine which method your API uses?
- Check the API documentation for details on authentication and authorization.
- Look for keywords like "session", "token", "JWT", or expiration time.
- If unsure, consult the API provider's support resources.
Here are some best practices for handling authentication with JSON-RPC APIs:
- Store tokens securely: If using tokens, store them securely in memory or a secure storage mechanism like the keychain. Avoid storing them in plain text.
- Refresh tokens before expiry: Monitor token expiry and refresh it before it expires to avoid interruptions in your application.
- Handle errors gracefully: Implement proper error handling for authentication failures.
By understanding the authentication method and implementing best practices, you can efficiently manage user sessions and keep your JSON-RPC interactions secure.
I know how authentication works and that there are other techniques that can be used. But I want to minimize the number of authentication calls for JSON-RPC. Does anyone know if that can be done once or needs to be done before each object call?
According to Odoo Support:
When using Odoo's JSON-RPC interface, you do not need to execute the authentication call before each object call. The authentication process should be done once to obtain the user ID and a session token, and then you can use these credentials for subsequent calls.