Skip to content

Commit

Permalink
allow custom auth endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Apr 20, 2018
1 parent f5d26ba commit 55ff84f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/backends/github/AuthenticationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down
9 changes: 7 additions & 2 deletions src/lib/netlify-auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { trim, trimEnd } from 'lodash';

const NETLIFY_API = 'https://api.netlify.com';
const AUTH_ENDPOINT = 'auth';

class NetlifyError {
constructor(err) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 55ff84f

Please sign in to comment.