Establishing client authorization using oAuth

tanordheim edited this page Sep 14, 2010 · 2 revisions

To establish a new client authorization using the oAuth integration, construct a new instance of the Freelancer::Client class, passing in the API token and API secret as arguments to the constructor, as such:

freelancer ="token", "secret")

You then need to capture the request token and request secret from the oAuth authorization and send the user to an authorization page where the oAuth authorization will be confirmed.

request_token = freelancer.request_token.token
request_secret = freelancer.request_token.secret
authorize_url = freelancer.request_token.authorize_url

When the user authorizes the application, you will be provided with a oAuth verification code that’s needed to finalize the authorization process. The process is finalized by using the captured request token and request secret, along with the oAuth verifier, as such:

freelancer.authorize_from_request(request_token, request_secret, "oauth verification key")

Finally, you need to capture the access token and access secret from the oAuth authorization as this will be used on subsequent accesses to the client API to prevent re-authorization:

access_token = freelancer.access_token.token
access_secret = freelancer.access_token.secret

Any time in the future (providing the application doesn’t get revoked by the user at when you need to access the client API, it can be instantiated like this:

freelancer ="token", "secret")
freelancer.authorize_from_access(access_token, access_secret)

The Freelancer API client is now ready for use.