Search code examples
iosobjective-capiafnetworkinginstapaper

When using AFXAuthClient, how do I keep the token and make further requests?


I'm making an app to integrate with Instapaper which uses the XAuth protocol for its API. I'm using AFXAuthClient, which is an extension for AFNetworking and I'm able to authenticate the user (using the method shown on AFXAuthClient's GitHub page), and in the success block I can make further queries to the API.

How do I now make further queries to the API now that the user is "logged in"? Say they add some more articles to their Instapaper queue and then tap the refresh button, how do I now query the Instapaper API again?

I'm aware I must save the credential/token I receive upon successful login, but I'm not sure how to do a request and say "Here's the token!" alongside of it.


Solution

  • Pass the token received from AFXAuthClient to your webservice-specific AFHTTPClient subclass using setAuthorizationHeaderWithToken:.

    Credentials should be saved using the keychain, and restored on application initialization.