Implementing Oauth
Implementing Oauth
About Me
Lorna Jane Mitchell PHP Consultant/Developer Occasional writer/speaker/trainer Twitter: @lornajane Website: http://lornajane.net
About Me
Lorna Jane Mitchell PHP Consultant/Developer Occasional writer/speaker/trainer Twitter: @lornajane Website: http://lornajane.net I am excited about OAuth :)
About OAuth
Provider has User data User wants data to be available to 3rd party User tells Provider to grant access to Consumer Access may be limited User can revoke at any time Provider can distinguish between User and Consumer
OAuth Terminology
Provider Consumer User Token Secret Verier The app with the interesting data The app that wants the data Who the data belongs to Random string Another random string, linked to a token Another random string
OAuth HowTo
OAuth Dance
Dance Steps
Step 0: Register as a consumer Step 1: Get a request token Step 2: Send the user to authenticate Step 3: Swap their verication for an access token Step 4: Consume data
Step 0: Register
Akin to registering for an API key Introduce the Provider and Consumer
10
11
The Provider returns them to us, at the callback URL, with a verier code
11
12
13
13
OAuth Theory
15
http://developer.yahoo.com/oauth/guide/oauth-requesttoken.html
We supplied the oauth_consumer_key and oauth_callback but what are these other elds?
16
17
17
17
17
17
17
Practical Examples
OAuth Tools
PHP tools for OAuth: Pecl OAuth http://uk2.php.net/manual/en/class.oauth.php Talk examples use this Zend OAuth http://framework.zend.com/manual/en/zend.oauth.html
19
Provider code with dark background Consumer code with a blue background
20
21
22
23
Step 1
24
25
26
27
28
29
30
31
Step 3
32
33
34
35
Step 4
consumer key, access token, API request Consumer API response Provider
36
37
Debugging
For pecl_oauth: Use OAuth::enableDebug() to turn on verbose debugging The debug information is available in OAuth::debugInfo For the provider, use OAuthProvider::reportProblem() Wireshark or Charles Proxy http://www.wireshark.org/ http://www.charlesproxy.com/
38
3-legged OAuth
So far we have discussed 3-legged OAuth Three parties are involved Consumer Provider User
40
2-legged OAuth
2-legged OAuth is also an option Only two parties involved now Provider User/Client Step 0: User signs up for credentials similar to consumer key/secret Step 4: User makes request using their key and secret empty token details
41
OAuth 2
Same principles and intention Spec still at draft stage ofcially Used by Google, Facebook and others Aims to be less complicated than OAuth 1 Intended to be more scalable - provider split into resources and auth servers No signing, SSL recommended instead
42
OAuth2 Outline
+--------+ +---------------+ | |--(A)- Authorization Request ->| Resource | | | | Owner | | |<-(B)-- Authorization Grant ---| | | | +---------------+ | | | | Authorization Grant & +---------------+ | |--(C)--- Client Credentials -->| Authorization | | Client | | Server | | |<-(D)----- Access Token -------| | | | +---------------+ | | | | +---------------+ | |--(E)----- Access Token ------>| Resource | | | | Server | | |<-(F)--- Protected Resource ---| | +--------+ +---------------+
Authorization Grant
Can take many forms Username and password used once to obtain an access token or just used as access token Client credentials client has prearranged access to the resource Implicit an access token provided some other way Authorization Code similar to OAuth 1, send user to talk to Auth Server and get verication codes
44
45
46
Questions?
Resources
PHP Manual: http://uk2.php.net/manual/en/book.oauth.php Rasmus OAuth Provider Example: http://bit.ly/i76Tzx Yahoo Developer Network Documentation:
http://developer.yahoo.com/oauth/guide/
Eran Hammer-Lahavs blog: http://hueniverse.com 2-legged OAuth post: http://bit.ly/ejQRoK OAuth 2 Draft Spec:
http://tools.ietf.org/html/draft-ietf-oauth-v2-15
48
Thanks!
Thanks!
http://joind.in/3243/
@lornajane
http://lornajane.net/
49