-
Notifications
You must be signed in to change notification settings - Fork 16
Subclassing CTCTDataStore causes invalid token error #3
Comments
The CTCTDataStore class isn't meant to be subclassed. The CTCTDataStore we include is actually just a template without implementation on most of the methods. The intent is, and you can look at the comments in the code, that a developer would implement their methods for storing and loading the tokens from the database in the Authentication.php file. If you subclassed the CTCTDataStore, you would have to also completely rewrite the Authentication.php classes that leverage the CTCTDataStore class as well (such as makeRequest()). I'd recommend for simplicity, you instead just implement all of the stub methods in the CTCTDataSTore class. |
Thanks for the response. Which code comments are you referring to? Authentication.php is lightly commented, and CTCTDataStore has minimal docs. Are you saying that I need to edit Authentication.php and change CTCTDataStore? If so, that seems to be strange for library as it means I'll have local edits that need to be merged with any future updates. Alternatively, do you have any code examples for initial authentication and subsequent reuse/lifecycle of an access token in a persistent store (not SESSION) as hinted at in config.php? |
While I did not write this library, it was created by one of our developer support members, I agree with you that it is odd. If I were to have written this, or if I had time to rewrite part of it, I would implement that DataStore feature as an interface that you would need to pass in the class for as part of the constructor instead. However, it was not written that way and I don't currently have the time to rewrite the authentication part (I'm a novice PHP developer so to do it right would take quite some time). Here are the methods that are stubs that would need to be implemented: function lookup_consumer($consumer_key) { function lookup_token($username) { } function lookup_nonce($consumer, $token, $nonce, $timestamp) { function new_request_token($consumer, $callback = null) { function new_access_token($token, $consumer, $verifier = null) { |
I've used your library and can successfully use the OAuth2 server flow to access the CTCT API and retrieve data. I've subclassed CTCTDataStore to store access credentials in database instead of a specific user session, but find I find CTCTDataStore is being called anyway and not by subclass. This causes the API request to fail since the session data doesn't contain current credentials.
Should I be registering my subclass somewhere? Do you have an example of using your library where CTCTDataStore is reimplemented?
The text was updated successfully, but these errors were encountered: