| Index: remoting/webapp/base/js/auth_init.js
|
| diff --git a/remoting/webapp/base/js/auth_init.js b/remoting/webapp/base/js/auth_init.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..944de5cd132c52033abdecfbae3a6c01ca7b8d6d
|
| --- /dev/null
|
| +++ b/remoting/webapp/base/js/auth_init.js
|
| @@ -0,0 +1,71 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +'use strict';
|
| +
|
| +/** @suppress {duplicate} */
|
| +var remoting = remoting || {};
|
| +
|
| +remoting.initIdentity = function() {
|
| + if (base.isAppsV2()) {
|
| + remoting.identity = new remoting.Identity(consentRequired_);
|
| + } else {
|
| + remoting.oauth2 = new remoting.OAuth2();
|
| + if (!remoting.oauth2.isAuthenticated()) {
|
| + document.getElementById('auth-dialog').hidden = false;
|
| + }
|
| + remoting.identity = remoting.oauth2;
|
| + }
|
| +
|
| + /** @param {remoting.Error} error */
|
| + var onGetEmailError = function(error) {
|
| + // No need to show the error message for NOT_AUTHENTICATED
|
| + // because we will show "auth-dialog".
|
| + if (error != remoting.Error.NOT_AUTHENTICATED) {
|
| + remoting.showErrorMessage(error);
|
| + }
|
| + }
|
| + remoting.identity.getEmail(remoting.onEmail, onGetEmailError);
|
| +}
|
| +
|
| +/**
|
| + * Display the user's email address and allow access to the rest of the app,
|
| + * including parsing URL parameters.
|
| + *
|
| + * @param {string} email The user's email address.
|
| + * @return {void} Nothing.
|
| + */
|
| +remoting.onEmail = function(email) {
|
| + document.getElementById('current-email').innerText = email;
|
| + document.getElementById('get-started-it2me').disabled = false;
|
| + document.getElementById('get-started-me2me').disabled = false;
|
| +};
|
| +
|
| +/**
|
| + * Show the authorization consent UI and register a one-shot event handler to
|
| + * continue the authorization process.
|
| + *
|
| + * @param {function():void} authContinue Callback to invoke when the user
|
| + * clicks "Continue".
|
| + */
|
| +function consentRequired_(authContinue) {
|
| + /** @type {HTMLElement} */
|
| + var dialog = document.getElementById('auth-dialog');
|
| + /** @type {HTMLElement} */
|
| + var button = document.getElementById('auth-button');
|
| + var consentGranted = function(event) {
|
| + dialog.hidden = true;
|
| + button.removeEventListener('click', consentGranted, false);
|
| + authContinue();
|
| + remoting.windowShape.updateClientWindowShape();
|
| + };
|
| + dialog.hidden = false;
|
| +
|
| + /** @type {HTMLElement} */
|
| + var dialog_border = document.getElementById('auth-dialog-border');
|
| + remoting.authDialog = new remoting.AuthDialog(dialog_border);
|
| + remoting.windowShape.addCallback(remoting.authDialog);
|
| +
|
| + button.addEventListener('click', consentGranted, false);
|
| +}
|
|
|