Skip to content

Commit

Permalink
[Chromoting] Change identity.getEmail -> identify.getUserInfo.
Browse files Browse the repository at this point in the history
When we use the identity API, this will now return both email and username *if
the webapp permissions allow it*.

Current CRD permissions request only the email and there are no plans to change
that, so CRD behavior will remain the same. The username field will be null.

The purpose of this cl is to allow CRD and AR (app-remoting - which has a
different set of webapp permissions) to share the same Identity code.

NOTRY=True
BUG=

Review URL: https://codereview.chromium.org/814983002

Cr-Commit-Position: refs/heads/master@{#309234}
  • Loading branch information
garykac authored and Commit bot committed Dec 19, 2014
1 parent 2a64a8c commit 76c6656
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
35 changes: 8 additions & 27 deletions remoting/webapp/crd/js/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,10 @@ remoting.Identity.prototype.removeCachedAuthToken = function(onDone) {
chrome.identity.getAuthToken({ 'interactive': false }, onToken);
};

/**
* Get the user's email address.
*
* @param {function(string):void} onOk Callback invoked when the email
* address is available.
* @param {function(remoting.Error):void} onError Callback invoked if an
* error occurs.
* @return {void} Nothing.
*/
remoting.Identity.prototype.getEmail = function(onOk, onError) {
/** @type {remoting.Identity} */
var that = this;
/** @param {string} email */
var onResponse = function(email) {
that.email_ = email;
that.fullName_ = null;
onOk(email);
};

this.callWithToken(
remoting.OAuth2Api.getEmail.bind(null, onResponse, onError), onError);
};

/**
* Get the user's email address and full name.
* The full name will be null unless the webapp has requested and been
* granted the userinfo.profile permission.
*
* @param {function(string,string):void} onOk Callback invoked when the user's
* email address and full name are available.
Expand All @@ -148,8 +127,8 @@ remoting.Identity.prototype.getUserInfo = function(onOk, onError) {
};

/**
* Get the user's email address, or null if no successful call to getEmail
* or getUserInfo has been made.
* Get the user's email address, or null if no successful call to getUserInfo
* has been made.
*
* @return {?string} The cached email address, if available.
*/
Expand All @@ -158,8 +137,10 @@ remoting.Identity.prototype.getCachedEmail = function() {
};

/**
* Get the user's full name, or null if no successful call to getUserInfo
* has been made.
* Get the user's full name.
* This will return null if either:
* No successful call to getUserInfo has been made, or
* The webapp doesn't have permission to access this value.
*
* @return {?string} The cached user's full name, if available.
*/
Expand Down
12 changes: 9 additions & 3 deletions remoting/webapp/crd/js/session_connector_impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,21 @@ remoting.SessionConnectorImpl.prototype.connectSignaling_ = function() {

/** @param {string} token */
function connectSignalingWithToken(token) {
remoting.identity.getEmail(
connectSignalingWithTokenAndEmail.bind(null, token), that.onError_);
remoting.identity.getUserInfo(
connectSignalingWithTokenAndUserInfo.bind(null, token), that.onError_);
}

/**
* Success callback for when the email and fullName have been retrieved
* for this user.
* Note that the full name will be null unless the webapp has requested
* and been granted the userinfo.profile permission.
*
* @param {string} token
* @param {string} email
* @param {string} fullName
*/
function connectSignalingWithTokenAndEmail(token, email) {
function connectSignalingWithTokenAndUserInfo(token, email, fullName) {
that.signalStrategy_.connect(
remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token);
}
Expand Down

0 comments on commit 76c6656

Please sign in to comment.