Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Subclassing CTCTDataStore causes invalid token error #3

Open
kayakr opened this issue Jun 28, 2012 · 3 comments
Open

Subclassing CTCTDataStore causes invalid token error #3

kayakr opened this issue Jun 28, 2012 · 3 comments

Comments

@kayakr
Copy link

kayakr commented Jun 28, 2012

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?

@daveberard
Copy link

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.

@kayakr
Copy link
Author

kayakr commented Jun 28, 2012

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?

@daveberard
Copy link

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) {
// optional: implement me
}

function lookup_token($username) {

}

function lookup_nonce($consumer, $token, $nonce, $timestamp) {
// optional: implement me
}

function new_request_token($consumer, $callback = null) {
// optional: return a new token attached to this consumer
}

function new_access_token($token, $consumer, $verifier = null) {
// return a new access token attached to this consumer
// for the user associated with this token if the request token
// is authorized
// should also invalidate the request token
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants