OLD | NEW |
1 <div id="pageData-name" class="pageData">Tutorial: OAuth</div> | 1 <div id="pageData-name" class="pageData">Tutorial: OAuth</div> |
2 <div id="pageData-showTOC" class="pageData">true</div> | 2 <div id="pageData-showTOC" class="pageData">true</div> |
3 | 3 |
4 <p> | 4 <p> |
5 <a href="http://oauth.net/">OAuth</a> is an open protocol that aims to standardi
ze the way desktop and web applications access a user's private data. OAuth prov
ides a mechanism for users to grant access to private data without sharing their
private credentials (username/password). Many sites have started enabling APIs
to use OAuth because of its security and standard set of libraries. | 5 <a href="http://oauth.net/">OAuth</a> is an open protocol that aims to standardi
ze the way desktop and web applications access a user's private data. OAuth prov
ides a mechanism for users to grant access to private data without sharing their
private credentials (username/password). Many sites have started enabling APIs
to use OAuth because of its security and standard set of libraries. |
6 </p> | 6 </p> |
7 <p> | 7 <p> |
8 This tutorial will walk you through the necessary steps for creating a Google Ch
rome Extension that uses OAuth to access an API. It leverages a library that you
can reuse in your extensions. | 8 This tutorial will walk you through the necessary steps for creating a Google Ch
rome Extension that uses OAuth to access an API. It leverages a library that you
can reuse in your extensions. |
9 </p> | 9 </p> |
10 <p> | 10 <p> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 'request_url': 'https://www.google.com/accounts/OAuthGetRequestToken', | 79 'request_url': 'https://www.google.com/accounts/OAuthGetRequestToken', |
80 'authorize_url': 'https://www.google.com/accounts/OAuthAuthorizeToken', | 80 'authorize_url': 'https://www.google.com/accounts/OAuthAuthorizeToken', |
81 'access_url': 'https://www.google.com/accounts/OAuthGetAccessToken', | 81 'access_url': 'https://www.google.com/accounts/OAuthGetAccessToken', |
82 'consumer_key': 'anonymous', | 82 'consumer_key': 'anonymous', |
83 'consumer_secret': 'anonymous', | 83 'consumer_secret': 'anonymous', |
84 'scope': 'https://docs.google.com/feeds/', | 84 'scope': 'https://docs.google.com/feeds/', |
85 'app_name': 'My Google Docs Extension' | 85 'app_name': 'My Google Docs Extension' |
86 }); | 86 }); |
87 </pre> | 87 </pre> |
88 | 88 |
| 89 <p> |
| 90 To use the OAuth library, |
| 91 you must declare the "tabs" permision in the |
| 92 <a href="http://code.google.com/chrome/extensions/manifest.html">extension manif
est</a>. |
| 93 You must also declare the sites you are using |
| 94 including the request URL, the authorize URL, access URL, |
| 95 and, if necessary, the scope URL. |
| 96 For example: |
| 97 </p> |
| 98 |
| 99 <pre> |
| 100 "permissions": [ "tabs", "https://docs.google.com/feeds/*", |
| 101 "https://www.google.com/accounts/OAuthGetRequestToken", |
| 102 "https://www.google.com/accounts/OAuthAuthorizeToken", |
| 103 "https://www.google.com/accounts/OAuthGetAccessToken" |
| 104 ] |
| 105 </pre> |
| 106 |
89 <h3 id="request-token">Fetching and authorizing a request token</h3> | 107 <h3 id="request-token">Fetching and authorizing a request token</h3> |
90 | 108 |
91 <p> | 109 <p> |
92 Once you have your background page set up, call the <code>authorize()</code> fun
ction to begin the OAuth dance and redirect the user to the OAuth provider. The
client library abstracts most of this process, so all you need to do is pass a c
allback to the <code>authorize()</code> function, and a new tab will open and re
direct the user. | 110 Once you have your background page set up, call the <code>authorize()</code> fun
ction to begin the OAuth dance and redirect the user to the OAuth provider. The
client library abstracts most of this process, so all you need to do is pass a c
allback to the <code>authorize()</code> function, and a new tab will open and re
direct the user. |
93 </p> | 111 </p> |
94 | 112 |
95 <pre> | 113 <pre> |
96 oauth.authorize(function() { | 114 oauth.authorize(function() { |
97 // ... Ready to fetch private data ... | 115 // ... Ready to fetch private data ... |
98 }); | 116 }); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 207 |
190 <p> | 208 <p> |
191 Sample extensions that use these techniques are available in the Chromium source
tree: | 209 Sample extensions that use these techniques are available in the Chromium source
tree: |
192 </p> | 210 </p> |
193 | 211 |
194 <ul> | 212 <ul> |
195 <li><a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/exten
sions/docs/examples/extensions/gdocs/">.../examples/extensions/gdocs/</a></li> | 213 <li><a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/exten
sions/docs/examples/extensions/gdocs/">.../examples/extensions/gdocs/</a></li> |
196 <li><a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/exten
sions/docs/examples/extensions/oauth_contacts/">.../examples/extensions/oauth_co
ntacts/</a></li> | 214 <li><a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/exten
sions/docs/examples/extensions/oauth_contacts/">.../examples/extensions/oauth_co
ntacts/</a></li> |
197 </ul> | 215 </ul> |
198 | 216 |
OLD | NEW |