Zend_Oauth-ProtocolWorkflow.xml 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.oauth.introduction.protocol-workflow">
  4. <title>Protocol Workflow</title>
  5. <para>
  6. Before implementing OAuth it makes sense to understand how the protocol operates. To do so
  7. we'll take the example of Twitter which currently implements OAuth based on the OAuth Core
  8. 1.0 Revision A Specification. This example looks at the protocol from the perspectives of
  9. the User (who will approve access), the Consumer (who is seeking access) and the Provider
  10. (who holds the User's private data). Access may be read-only or read and write.
  11. </para>
  12. <para>
  13. By chance, our User has decided that they want to utilise a new service called TweetExpress
  14. which claims to be capable of reposting your blog posts to Twitter in a manner of seconds.
  15. TweetExpress is a registered application on Twitter meaning that it has access to a Consumer
  16. Key and a Consumer Secret (all OAuth applications must have these from the Provider they
  17. will be accessing) which identify its requests to Twitter and that ensure all requests can
  18. be signed using the Consumer Secret to verify their origin.
  19. </para>
  20. <para>
  21. To use TweetExpress you are asked to register for a new account, and after your registration
  22. is confirmed you are informed that TweetExpress will seek to associate your Twitter account
  23. with the service.
  24. </para>
  25. <para>
  26. In the meantime TweetExpress has been busy. Before gaining your approval from Twitter, it
  27. has sent a <acronym>HTTP</acronym> request to Twitter's service asking for a new
  28. unauthorized Request Token. This token is not User specific from Twitter's perspective, but
  29. TweetExpress may use it specifically for the current User and should associate it with their
  30. account and store it for future use. TweetExpress now redirects the User to Twitter so they
  31. can approve TweetExpress' access. The URL for this redirect will be signed using
  32. TweetExpress' Consumer Secret and it will contain the unauthorized Request Token as a
  33. parameter.
  34. </para>
  35. <para>
  36. At this point the User may be asked to log into Twitter and will now be faced with a Twitter
  37. screen asking if they approve this request by TweetExpress to access Twitter's
  38. <acronym>API</acronym> on the User's behalf. Twitter will record the response which we'll
  39. assume was positive. Based on the User's approval, Twitter will record the current
  40. unauthorized Request Token as having been approved by the User (thus making it User
  41. specific) and will generate a new value in the form of a verification code. The User is now
  42. redirected back to a specific callback URL used by TweetExpress (this callback URL may be
  43. registered with Twitter or dynamically set using an oauth_callback parameter in requests).
  44. The redirect URL will contain the newly generated verification code.
  45. </para>
  46. <para>
  47. TweetExpress' callback URL will trigger an examination of the response to determine whether
  48. the User has granted their approval to Twitter. Assuming so, it may now exchange it's
  49. unauthorized Request Token for a fully authorized Access Token by sending a request back to
  50. Twitter including the Request Token and the received verification code. Twitter should now
  51. send back a response containing this Access Token which must be used in all requests used to
  52. access Twitter's <acronym>API</acronym> on behalf of the User. Twitter will only do this
  53. once they have confirmed the attached Request Token has not already been used to retrieve
  54. another Access Token. At this point, TweetExpress may confirm the receipt of the approval to
  55. the User and delete the original Request Token which is no longer needed.
  56. </para>
  57. <para>
  58. From this point forward, TweetExpress may use Twitter's <acronym>API</acronym> to post new
  59. tweets on the User's behalf simply by accessing the <acronym>API</acronym> endpoints with a
  60. request that has been digitally signed (via HMAC-SHA1) with a combination of TweetExpress'
  61. Consumer Secret and the Access Key being used.
  62. </para>
  63. <para>
  64. Although Twitter do not currently expire Access Tokens, the User is free to deauthorize
  65. TweetExpress from their Twitter account settings. Once deauthorized, TweetExpress' access
  66. will be cut off and their Access Token rendered invalid.
  67. </para>
  68. </sect2>