-
Notifications
You must be signed in to change notification settings - Fork 8
Getting Started
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
- Supports OAuth1.0a and 2.0
- OAuth1.0 and 2.0 API ready to use
- Simple to create new OAuth API bindings.
Require EiffelStudio 7.3, depends on eel and json
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, in this case Linkedin as the API provider. By default an out of band callback is defined, but you can set a callback Url using with_callback_url, before to call build.
Get the request token
request_token : detachable OAUTH_TOKEN
request_token := api_service.request_token
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 := api_service.access_token_get (request_token, create {OAUTH_VERIFIER}.make (io.last_string))
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
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
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
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/