An important part of any Podio API integration is managing your authentication tokens. You can avoid hitting rate limits and make your integration faster by storing authentication tokens and thus avoid having to re-authenticate every time your script runs.
What is a session manager
When you setup the API client you can optionally pass in the name of a session manager. This can be the class name of your session manager class or an instance of a session manager. This class handles storing and retrieving access tokens through a unified interface. For example if your class is called PodioSession you would setup your client as:
If you use a session manager your authentication tokens will automatically be stored at the end of your script run (more specifically when the PodioClient is destroyed/destructed) and automatically retrieved when you create your client at the beginning of the following script run.
Writing your own session manager
Writing a session manager is straight-forward. You need to create a new class that has two methods: get and set.
The get method
The get method should retrieve an existing authentication when called.
It should return a PodioOAuth object in all cases. Return an empty PodioOAuth object if no existing authentication could be found.
The set method
The set method should store a PodioOAuth object when called. It has two parameters, $oauth, which holds the current PodioOAuth object and $auth_type, which contains information about the current authentication method when using app or password authentication. This makes it easier to switch between multiple forms of authentication (see below).
Example: Store access tokens in browser session cookie
This is a simple example meant for a web application that uses the server-side authentication flow. It stores the authentication data in a session cookie.
Save the above class and include it in your project. You can now use this session manager:
Example: Store access tokens in Redis
This is a simple example of how you could store authentication data in Redis.
Save the above class and include it in your project. You can now use this session manager: