diff --git a/extensions/amp-access-laterpay/0.1/laterpay-impl.js b/extensions/amp-access-laterpay/0.1/laterpay-impl.js index e11ea71d5e189..4f7905499a941 100644 --- a/extensions/amp-access-laterpay/0.1/laterpay-impl.js +++ b/extensions/amp-access-laterpay/0.1/laterpay-impl.js @@ -219,12 +219,13 @@ export class LaterpayVendor { const urlPromise = this.accessService_.buildUrl( url, /* useAuthData */ false); return urlPromise.then(url => { - dev().fine(TAG, 'Authorization URL: ', url); + return this.accessService_.buildLoginUrl(url); + }).then(url => { + dev().info(TAG, 'Authorization URL: ', url); return this.timer_.timeoutPromise( AUTHORIZATION_TIMEOUT, this.xhr_.fetchJson(url, { credentials: 'include', - requireAmpResponseSourceOrigin: true, })); }); } diff --git a/extensions/amp-access/0.1/amp-access.js b/extensions/amp-access/0.1/amp-access.js index 0fac41e4cc119..a5172c99c594a 100644 --- a/extensions/amp-access/0.1/amp-access.js +++ b/extensions/amp-access/0.1/amp-access.js @@ -34,7 +34,7 @@ import {isExperimentOn} from '../../../src/experiments'; import {isObject} from '../../../src/types'; import {listenOnce} from '../../../src/event-helper'; import {dev, user} from '../../../src/log'; -import {openLoginDialog} from './login-dialog'; +import {getLoginUrl, openLoginDialog} from './login-dialog'; import {parseQueryString} from '../../../src/url'; import {performanceForOrNull} from '../../../src/services'; import {resourcesForDoc} from '../../../src/services'; @@ -157,6 +157,8 @@ export class AccessService { /** @private @const {function(string):Promise} */ this.openLoginDialog_ = openLoginDialog.bind(null, ampdoc); + this.getLoginUrl_ = getLoginUrl.bind(null, ampdoc); + /** @private {?Promise} */ this.readerIdPromise_ = null; @@ -919,8 +921,16 @@ export class AccessService { } return Promise.all(promises); } -} + /** + * @param {string} url + * @return {string} + */ + buildLoginUrl(url) { + return this.getLoginUrl_(url); + } + +} /** * @typedef {{ diff --git a/extensions/amp-access/0.1/login-dialog.js b/extensions/amp-access/0.1/login-dialog.js index 30c5079997312..f267dba14ffa8 100644 --- a/extensions/amp-access/0.1/login-dialog.js +++ b/extensions/amp-access/0.1/login-dialog.js @@ -46,6 +46,15 @@ export function openLoginDialog(ampdoc, urlOrPromise) { return new WebLoginDialog(ampdoc.win, viewer, urlOrPromise).open(); } +export function getLoginUrl(ampdoc, urlOrPromise) { + const viewer = viewerForDoc(ampdoc); + const overrideDialog = parseInt(viewer.getParam('dialog'), 10); + if (overrideDialog) { + return new ViewerLoginDialog(viewer, urlOrPromise).getLoginUrl(); + } + return new WebLoginDialog(ampdoc.win, viewer, urlOrPromise).getLoginUrl(); +} + /** * The implementation of the Login Dialog delegated via Viewer. @@ -63,13 +72,7 @@ class ViewerLoginDialog { this.urlOrPromise = urlOrPromise; } - /** - * Opens the dialog. Returns the promise that will yield with the dialog's - * result or will be rejected if dialog fails. The dialog's result is - * typically a hash string from the return URL. - * @return {!Promise} - */ - open() { + getLoginUrl() { let urlPromise; if (typeof this.urlOrPromise == 'string') { urlPromise = Promise.resolve(this.urlOrPromise); @@ -77,13 +80,26 @@ class ViewerLoginDialog { urlPromise = this.urlOrPromise; } return urlPromise.then(url => { - const loginUrl = buildLoginUrl(url, 'RETURN_URL'); + return buildLoginUrl(url, 'RETURN_URL'); + }); + } + + + /** + * Opens the dialog. Returns the promise that will yield with the dialog's + * result or will be rejected if dialog fails. The dialog's result is + * typically a hash string from the return URL. + * @return {!Promise} + */ + open() { + return this.getLoginUrl().then(loginUrl => { dev().fine(TAG, 'Open viewer dialog: ', loginUrl); return this.viewer.sendMessageAwaitResponse('openDialog', { 'url': loginUrl, }); }); } + } @@ -172,6 +188,11 @@ export class WebLoginDialog { } } + getLoginUrl() { + const returnUrl = this.getReturnUrl_(); + return buildLoginUrl(this.urlOrPromise, returnUrl); + } + /** @private */ openInternal_() { const screen = this.win.screen; @@ -297,7 +318,6 @@ export class WebLoginDialog { * @param {string} url * @param {string} returnUrl * @return {string} - * @private */ function buildLoginUrl(url, returnUrl) { // RETURN_URL has to arrive here unreplaced by UrlReplacements for two