Skip to content
jvelilla edited this page Aug 23, 2013 · 13 revisions

This document assume that you know OAuth, in other case there are a lot of tutorials. Look at the end of this tutorial to read about the specific OAuth version.

Eiffel library OAuth1.0a and OAuth2.0, consumer library based on Scribe Java Library

Features

  • Supports OAuth1.0a and 2.0
  • OAuth1.0 and 2.0 API ready to use
  • Simple to create new OAuth API bindings.

Setup

Require EiffelStudio 7.3, depends on eel and json

Initialization

Before to start you will need to create a service for a particular OAuth API consumer (for example Twiter, Linkedin, etc).

api_service : OAUTH_SERVICE_I
api_builder: API_BUILDER	

    create api_builder
api_service := api_builder.with_api (create {OAUTH_10_LINKEDIN_API})
			.with_api_key (api_key)											     
                            .with_api_secret (api_secret)
			.build

As you can see we use an instance of API_BUILDER to create a service using in this case a LINKEDIN as the API provider, you can use this builder for both OAuth version.

Request Token Get the request token

request_token : detachable OAUTH_TOKEN

request_token := api_service.request_token

Authorization Request

	if attached api_service.authorization_url (request_token) as lauthorization_url then
	    print("%NGot the Authorization URL!%N");
	    print(lauthorization_url);
	    print("%NAnd paste the authorization code here%N");
	    io.read_line
end

Access Token Request access_token := api_service.access_token_get (request_token, create {OAUTH_VERIFIER}.make (io.last_string))

Refreshing Access Token (Only OAuth2.0)

Resource Request

 create request.make ("GET", protected_resource_url)
 api_service.sign_request (l_access_token, request)
 if attached {OAUTH_RESPONSE} request.execute as l_response then
	print ("%NOk, let see what we found...")
	print ("%NResponse: STATUS" + l_response.status.out)
	if attached l_response.body as l_body then
	print ("%NBody:"+l_body)
 end

Examples How to add a new OAuth1.0a service provider.

Inherit from OAUTH_10_TEMPLATE_API and complete the values for: authorize_url, request_token_endpoint_url, and access_token_endpoint_url.

Let see an example for Linkedin1.0a, read the documentation and retrieve the needed information.

class OAUTH_10_LINKEDIN_API

inherit

OAUTH_10_TEMPLATE_API

feature {NONE} -- Implementation

authorize_url: STRING ="https://api.linkedin.com/uas/oauth/authenticate?oauth_token="

request_token_endpoint_url: STRING = "https://api.linkedin.com/uas/oauth/requestToken"

access_token_endpoint_url: STRING = "https://api.linkedin.com/uas/oauth/accessToken"

end

2-Legged’ OAuth10a Example : Yelp APIv2

class OAUTH_10_YELPv2_API

inherit

OAUTH_10_TEMPLATE_API

feature {NONE} -- Implementation

authorize_url: STRING =""

request_token_endpoint_url: STRING = ""

access_token_endpoint_url: STRING = ""

end

OAuth Consumer Provider WebAPi GoogleAPI

How to add a new OAuth2.0 service provider. Inherit from OAUTH_20_API,

Example OAUTH_20_GOOGLE_API

Quality: unstable, draft, in-progress

OAuth1.0 http://tools.ietf.org/html/rfc5849 http://oauth.net/core/1.0a/

OAuth2.0 http://oauth.net/2/

Clone this wiki locally