diff --git a/src/backends/github/AuthenticationPage.js b/src/backends/github/AuthenticationPage.js index 20e6888e987e..cb3274414d6d 100644 --- a/src/backends/github/AuthenticationPage.js +++ b/src/backends/github/AuthenticationPage.js @@ -7,6 +7,9 @@ export default class AuthenticationPage extends React.Component { static propTypes = { onLogin: PropTypes.func.isRequired, inProgress: PropTypes.bool, + base_url: PropTypes.string, + siteId: PropTypes.string, + authEndpoint: PropTypes.string, }; state = {}; @@ -15,7 +18,8 @@ export default class AuthenticationPage extends React.Component { e.preventDefault(); const cfg = { base_url: this.props.base_url, - site_id: (document.location.host.split(':')[0] === 'localhost') ? 'cms.netlify.com' : this.props.siteId + site_id: (document.location.host.split(':')[0] === 'localhost') ? 'cms.netlify.com' : this.props.siteId, + auth_endpoint: this.props.authEndpoint, }; const auth = new Authenticator(cfg); diff --git a/src/components/App/App.js b/src/components/App/App.js index 1613e59d5a21..d3dbcf7d198a 100644 --- a/src/components/App/App.js +++ b/src/components/App/App.js @@ -84,6 +84,7 @@ class App extends React.Component { isFetching: auth && auth.get('isFetching'), siteId: this.props.config.getIn(["backend", "site_domain"]), base_url: this.props.config.getIn(["backend", "base_url"], null), + authEndpoint: this.props.config.getIn(["backend", "auth_endpoint"]), config: this.props.config, }) } diff --git a/src/lib/netlify-auth.js b/src/lib/netlify-auth.js index b22b8c6beeab..9f47aef31608 100644 --- a/src/lib/netlify-auth.js +++ b/src/lib/netlify-auth.js @@ -1,4 +1,7 @@ +import { trim, trimEnd } from 'lodash'; + const NETLIFY_API = 'https://api.netlify.com'; +const AUTH_ENDPOINT = 'auth'; class NetlifyError { constructor(err) { @@ -31,7 +34,8 @@ const PROVIDERS = { class Authenticator { constructor(config = {}) { this.site_id = config.site_id || null; - this.base_url = config.base_url || NETLIFY_API; + this.base_url = trimEnd(config.base_url, '/') || NETLIFY_API; + this.auth_endpoint = trim(config.auth_endpoint, '/') || AUTH_ENDPOINT; } handshakeCallback(options, cb) { @@ -90,10 +94,11 @@ class Authenticator { } const conf = PROVIDERS[provider] || PROVIDERS.github; + const authEndpoint = config. left = (screen.width / 2) - (conf.width / 2); top = (screen.height / 2) - (conf.height / 2); window.addEventListener('message', this.handshakeCallback(options, cb), false); - url = this.base_url + '/auth?provider=' + options.provider + '&site_id=' + siteID; + url = `${this.base_url}/${this.auth_endpoint}?provider=${options.provider}&site_id=${siteID}`; if (options.scope) { url += '&scope=' + options.scope; }