OLD | NEW |
1 <h1>Identify User</h1> | 1 <h1>Identify User</h1> |
2 | 2 |
3 | 3 |
4 <p> | 4 <p> |
5 Web authentication protocols utilize HTTP features, | 5 Web authentication protocols utilize HTTP features, |
6 but packaged apps run inside the app container; | 6 but packaged apps run inside the app container; |
7 they don’t load over HTTP and can’t perform redirects or set cookies. | 7 they don’t load over HTTP and can’t perform redirects or set cookies. |
8 </p> | 8 </p> |
9 | 9 |
10 <p> | 10 <p> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 </p> | 51 </p> |
52 | 52 |
53 <ol> | 53 <ol> |
54 <li>Add permissions to your manifest and upload your app.</li> | 54 <li>Add permissions to your manifest and upload your app.</li> |
55 <li>Copy key in the installed <code>manifest.json</code> to your source
manifest.</li> | 55 <li>Copy key in the installed <code>manifest.json</code> to your source
manifest.</li> |
56 <li>Get your client ID.</li> | 56 <li>Get your client ID.</li> |
57 <li>Update your manifest to include the client ID and scopes.</li> | 57 <li>Update your manifest to include the client ID and scopes.</li> |
58 <li>Get the authentication token.</li> | 58 <li>Get the authentication token.</li> |
59 </ol> | 59 </ol> |
60 | 60 |
61 <h3>Add permissions and upload app</h3> | 61 <h3 id="add_permissions">Add permissions and upload app</h3> |
62 | 62 |
63 <p> | 63 <p> |
64 The identity API is still experimental. | 64 The identity API is still experimental. |
65 You need to make sure the experimental | 65 You need to make sure the experimental |
66 and identity permissions are in your manifest. | 66 and identity permissions are in your manifest. |
67 You can then upload your app to the apps and extensions management page | 67 You can then upload your app to the apps and extensions management page |
68 (see <a href="publish_app.html">Publish</a>). | 68 (see <a href="publish_app.html">Publish</a>). |
69 </p> | 69 </p> |
70 | 70 |
71 <pre> | 71 <pre> |
72 "permissions": [ | 72 "permissions": [ |
73 "experimental", | 73 "experimental", |
74 "identity" | 74 "identity" |
75 ] | 75 ] |
76 </pre> | 76 </pre> |
77 | 77 |
78 <h3>Copy key to your manifest</h3> | 78 <h3 id="copy_key">Copy key to your manifest</h3> |
79 | 79 |
80 <p> | 80 <p> |
81 You need to copy the key in the installed | 81 You need to copy the key in the installed |
82 <code>manifest.json</code> to your source manifest. | 82 <code>manifest.json</code> to your source manifest. |
83 This ensures that the key isn't overridden anytime your reload your app | 83 This ensures that the key isn't overridden anytime your reload your app |
84 or share the app with other users. | 84 or share the app with other users. |
85 It's not the most graceful task, but here's how it goes: | 85 It's not the most graceful task, but here's how it goes: |
86 </p> | 86 </p> |
87 | 87 |
88 <ol> | 88 <ol> |
89 <li>Go to your | 89 <li>Go to your |
90 <a href="http://www.chromium.org/user-experience/user-data-direc
tory">user data directory</a>. | 90 <a href="http://www.chromium.org/user-experience/user-data-direc
tory">user data directory</a>. |
91 Example on MacOs: <code>~/Library/Application\ Support/Google/Ch
rome/Default/Extensions</code></li> | 91 Example on MacOs: <code>~/Library/Application\ Support/Google/Ch
rome/Default/Extensions</code></li> |
92 <li>List the installed apps and extensions and match your app ID on the
apps and extensions management page | 92 <li>List the installed apps and extensions and match your app ID on the
apps and extensions management page |
93 to the same ID here.</li> | 93 to the same ID here.</li> |
94 <li>Go to the installed app directory (this will be a version within the
app ID). | 94 <li>Go to the installed app directory (this will be a version within the
app ID). |
95 Open the installed <code>manifest.json</code> | 95 Open the installed <code>manifest.json</code> |
96 (pico is a quick way to open the file).</li> | 96 (pico is a quick way to open the file).</li> |
97 <li>Copy the "key" in the installed <code>manifest.json</code> and paste
it into your app's source manifest file.</li> | 97 <li>Copy the "key" in the installed <code>manifest.json</code> and paste
it into your app's source manifest file.</li> |
98 </ol> | 98 </ol> |
99 | 99 |
100 <h3>Get your client ID</h3> | 100 <h3 id="client_id">Get your client ID</h3> |
101 | 101 |
102 <p> | 102 <p> |
103 Setting up the client ID is currently not available externally | 103 Setting up the client ID is currently not available externally |
104 via <a href="https://devconsole-canary.corp.google.com/apis/">Google APIs Consol
e</a>. | 104 via <a href="https://devconsole-canary.corp.google.com/apis/">Google APIs Consol
e</a>. |
105 So to setup the OAuth2 client ID, | 105 So to setup the OAuth2 client ID, |
106 email <a href="mailto:chrome-apps-auth-requests@google.com">chrome-apps-auth-req
uest@google.com</a> | 106 email <a href="mailto:chrome-apps-auth-requests@google.com">chrome-apps-auth-req
uest@google.com</a> |
107 with your stable app ID and | 107 with your stable app ID and |
108 we will reply appropriately with your OAuth2 client ID. | 108 we will reply appropriately with your OAuth2 client ID. |
109 </p> | 109 </p> |
110 | 110 |
111 <h3>Update your manifest</h3> | 111 <h3 id="update_manifest">Update your manifest</h3> |
112 | 112 |
113 <p> | 113 <p> |
114 You need to update your manifest to include | 114 You need to update your manifest to include |
115 the client ID and scopes. | 115 the client ID and scopes. |
116 Here's the sample "oauth2" for the | 116 Here's the sample "oauth2" for the |
117 <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/gdocs">g
docs sample</a>: | 117 <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/gdocs">g
docs sample</a>: |
118 </p> | 118 </p> |
119 | 119 |
120 <pre> | 120 <pre> |
121 "oauth2": { | 121 "oauth2": { |
122 "client_id": "665859454684.apps.googleusercontent.com", | 122 "client_id": "665859454684.apps.googleusercontent.com", |
123 "scopes": [ | 123 "scopes": [ |
124 "https://docs.google.com/feeds/", | 124 "https://docs.google.com/feeds/", |
125 "https://docs.googleusercontent.com/", | 125 "https://docs.googleusercontent.com/", |
126 "https://spreadsheets.google.com/feeds/", | 126 "https://spreadsheets.google.com/feeds/", |
127 "https://www.googleapis.com/auth/drive.file" | 127 "https://www.googleapis.com/auth/drive.file" |
128 ] | 128 ] |
129 } | 129 } |
130 </pre> | 130 </pre> |
131 | 131 |
132 <h3>Get the token</h3> | 132 <h3 id="token">Get the token</h3> |
133 | 133 |
134 <p> | 134 <p> |
135 You are now ready to get the auth token: | 135 You are now ready to get the auth token: |
136 </p> | 136 </p> |
137 | 137 |
138 <pre> | 138 <pre> |
139 chrome.experimental.identity.getAuthToken(function(token) { }) | 139 chrome.experimental.identity.getAuthToken(function(token) { }) |
140 </pre> | 140 </pre> |
141 | 141 |
142 <h2 id="non">Non-Google account authentication</h2> | 142 <h2 id="non">Non-Google account authentication</h2> |
143 | 143 |
144 <p> | 144 <p> |
145 Here are the three steps you need to complete: | 145 Here are the three steps you need to complete: |
146 </p> | 146 </p> |
147 | 147 |
148 <ol> | 148 <ol> |
149 <li>Register with the provider.</li> | 149 <li>Register with the provider.</li> |
150 <li>Add permissions for provider resources that your app will access.</l
i> | 150 <li>Add permissions for provider resources that your app will access.</l
i> |
151 <li>Get the authentication token.</li> | 151 <li>Get the authentication token.</li> |
152 </ol> | 152 </ol> |
153 | 153 |
154 <h3>Register with the provider</h3> | 154 <h3 id="register_provider">Register with the provider</h3> |
155 | 155 |
156 <p> | 156 <p> |
157 You need to register an OAuth2 client ID with the provider | 157 You need to register an OAuth2 client ID with the provider |
158 and configure the client ID as a website. | 158 and configure the client ID as a website. |
159 For the redirect URI to be entered during registration, | 159 For the redirect URI to be entered during registration, |
160 use the URL of the form: | 160 use the URL of the form: |
161 <code>https://<extension-id>.chromiumapp.org/<anything-here></code> | 161 <code>https://<extension-id>.chromiumapp.org/<anything-here></code> |
162 </p> | 162 </p> |
163 | 163 |
164 <p> | 164 <p> |
165 For example, if you app ID is abcdefghijklmnopqrstuvwxyzabcdef and | 165 For example, if you app ID is abcdefghijklmnopqrstuvwxyzabcdef and |
166 you want provider_cb to be the path, | 166 you want provider_cb to be the path, |
167 to distinguish it with redirect URIs from other providers, | 167 to distinguish it with redirect URIs from other providers, |
168 you should use: | 168 you should use: |
169 <code>https://abcdefghijklmnopqrstuvwxyzabcdef.chromiumapp.org/provider_cb</code
> | 169 <code>https://abcdefghijklmnopqrstuvwxyzabcdef.chromiumapp.org/provider_cb</code
> |
170 </p> | 170 </p> |
171 | 171 |
172 <h3>Add permissions for provider</h3> | 172 <h3 id="permissions_provider">Add permissions for provider</h3> |
173 | 173 |
174 <p> | 174 <p> |
175 To make cross-original XHRs to Google API endpoints, | 175 To make cross-original XHRs to Google API endpoints, |
176 you need to whitelist those patterns in the permissions: | 176 you need to whitelist those patterns in the permissions: |
177 </p> | 177 </p> |
178 | 178 |
179 <pre> | 179 <pre> |
180 "permissions": [ | 180 "permissions": [ |
181 ... | 181 ... |
182 "https://docs.google.com/feeds/", | 182 "https://docs.google.com/feeds/", |
183 "https://docs.googleusercontent.com/", | 183 "https://docs.googleusercontent.com/", |
184 “https://www.website-of-provider-with-user-photos.com/photos/” | 184 “https://www.website-of-provider-with-user-photos.com/photos/” |
185 ] | 185 ] |
186 </pre> | 186 </pre> |
187 | 187 |
188 <h3>Get the token</h3> | 188 <h3 id="token2">Get the token</h3> |
189 | 189 |
190 <p> | 190 <p> |
191 To get the token: | 191 To get the token: |
192 </p> | 192 </p> |
193 | 193 |
194 <pre> | 194 <pre> |
195 chrome.experimental.identity.launchWebAuthFlow( | 195 chrome.experimental.identity.launchWebAuthFlow( |
196 {‘url’: ‘<url-to-do-auth>’, ‘interactive’: true}, | 196 {‘url’: ‘<url-to-do-auth>’, ‘interactive’: true}, |
197 function(redirect_url) { // Extract token from redirect_url }); | 197 function(redirect_url) { // Extract token from redirect_url }); |
198 </pre> | 198 </pre> |
(...skipping 12 matching lines...) Expand all Loading... |
211 It will then redirect to | 211 It will then redirect to |
212 <code>https://abcdefghijklmnopqrstuvwxyzabcdef.chromiumapp.org/provider_cb#authT
oken=<auth-token></code> | 212 <code>https://abcdefghijklmnopqrstuvwxyzabcdef.chromiumapp.org/provider_cb#authT
oken=<auth-token></code> |
213 </p> | 213 </p> |
214 | 214 |
215 <p> | 215 <p> |
216 Chrome will capture that and invoke the callback | 216 Chrome will capture that and invoke the callback |
217 of the app with the full redirect URL. | 217 of the app with the full redirect URL. |
218 The app should extract the token out of the URL. | 218 The app should extract the token out of the URL. |
219 </p> | 219 </p> |
220 | 220 |
221 <h3>Interactive versus silent mode</h3> | 221 <h3 id="interactive">Interactive versus silent mode</h3> |
222 | 222 |
223 <p> | 223 <p> |
224 When calling <code>launchWebAuthFlow</code>, | 224 When calling <code>launchWebAuthFlow</code>, |
225 you can pass a flag (‘interactive’: true in the example above) | 225 you can pass a flag (‘interactive’: true in the example above) |
226 indicating whether you want the API to be called | 226 indicating whether you want the API to be called |
227 in interactive mode or not (aka silent mode). | 227 in interactive mode or not (aka silent mode). |
228 If you invoke the API in interactive mode, | 228 If you invoke the API in interactive mode, |
229 the user is shown UI, if necessary, | 229 the user is shown UI, if necessary, |
230 to get the token (signin UI and/or approval UI; | 230 to get the token (signin UI and/or approval UI; |
231 or for that matter any provider specific UI). | 231 or for that matter any provider specific UI). |
232 </p> | 232 </p> |
233 | 233 |
234 <p> | 234 <p> |
235 If you invoke the API in silent mode, | 235 If you invoke the API in silent mode, |
236 the API will only return a token if the provider is able | 236 the API will only return a token if the provider is able |
237 to provide a token without showing any UI. | 237 to provide a token without showing any UI. |
238 This is useful in cases when an app is doing the flow at app startup, for exampl
e, | 238 This is useful in cases when an app is doing the flow at app startup, for exampl
e, |
239 or in general in cases where there is no user gesture involved. | 239 or in general in cases where there is no user gesture involved. |
240 </p> | 240 </p> |
241 | 241 |
242 <p> | 242 <p> |
243 The best practice we suggest is to use silent mode | 243 The best practice we suggest is to use silent mode |
244 when there is no user gesture involved and use interactive mode | 244 when there is no user gesture involved and use interactive mode |
245 if there is a user gesture (for example, the user clicked the Sign In button in
your app). | 245 if there is a user gesture (for example, the user clicked the Sign In button in
your app). |
246 Note that we do not enforce gesture requirement. | 246 Note that we do not enforce gesture requirement. |
247 </p> | 247 </p> |
248 | 248 |
249 <p class="backtotop"><a href="#top">Back to top</a></p> | 249 <p class="backtotop"><a href="#top">Back to top</a></p> |
OLD | NEW |