1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * OAuth2 API flow implementations.
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
16 remoting.OAuth2Api = function() {
20 * Asynchronously retrieves a new access token from the server.
22 * @param {function(string, number): void} onDone Callback to invoke when
23 * the access token and expiration time are successfully fetched.
24 * @param {function(!remoting.Error):void} onError Callback invoked if an
26 * @param {string} clientId OAuth2 client ID.
27 * @param {string} clientSecret OAuth2 client secret.
28 * @param {string} refreshToken OAuth2 refresh token to be redeemed.
29 * @return {void} Nothing.
31 remoting.OAuth2Api.prototype.refreshAccessToken = function(
32 onDone, onError, clientId, clientSecret, refreshToken) {
36 * Asynchronously exchanges an authorization code for access and refresh tokens.
38 * @param {function(string, string, number): void} onDone Callback to
39 * invoke when the refresh token, access token and access token expiration
40 * time are successfully fetched.
41 * @param {function(!remoting.Error):void} onError Callback invoked if an
43 * @param {string} clientId OAuth2 client ID.
44 * @param {string} clientSecret OAuth2 client secret.
45 * @param {string} code OAuth2 authorization code.
46 * @param {string} redirectUri Redirect URI used to obtain this code.
47 * @return {void} Nothing.
49 remoting.OAuth2Api.prototype.exchangeCodeForTokens = function(
50 onDone, onError, clientId, clientSecret, code, redirectUri) {
54 * Get the user's email address.
56 * TODO(jamiewalch): Reorder these parameters to match the typical chrome API
57 * convention of having callbacks at the end and remove the token parameter
58 * to match remoting.HostListApi.
60 * @param {function(string):void} onDone Callback invoked when the email
61 * address is available.
62 * @param {function(!remoting.Error):void} onError Callback invoked if an
64 * @param {string} token Access token.
65 * @return {void} Nothing.
67 remoting.OAuth2Api.prototype.getEmail = function(onDone, onError, token) {
71 * Get the user's email address and full name.
73 * @param {function(string, string):void} onDone Callback invoked when the email
74 * address and full name are available.
75 * @param {function(!remoting.Error):void} onError Callback invoked if an
77 * @param {string} token Access token.
78 * @return {void} Nothing.
80 remoting.OAuth2Api.prototype.getUserInfo = function(onDone, onError, token) {