From 5cbba0089968e2d26ee05fb1b8b1b58bc99d80df Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Fri, 16 Feb 2018 14:33:27 -0700 Subject: [PATCH] github urls --- app/verify-auth/route.js | 10 ++--- .../authentication/github/template.hbs | 2 +- lib/shared/addon/github/service.js | 41 +++++++++---------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/app/verify-auth/route.js b/app/verify-auth/route.js index 63ecde913..9312dca17 100644 --- a/app/verify-auth/route.js +++ b/app/verify-auth/route.js @@ -50,8 +50,8 @@ export default Route.extend({ return gh.testConfig(config).then((resp) => { // TODO build with url building Util - let redirect = `${get(resp, 'redirectUrl')}&redirect_uri=${window.location.origin}/verify-auth?authProvider=github&state=${openerController.get('github.state')}&scope=read:org`; - window.location.href = redirect; + // let redirect = `${get(resp, 'redirectUrl')}&redirect_uri=${window.location.origin}/verify-auth?authProvider=github&state=${}&scope=read:org`; + gh.getAuthorizeUrl(resp, openerController.get('github.state')); }).catch(err => { this.send('gotError', err); }); @@ -70,15 +70,15 @@ export default Route.extend({ } if (get(params, 'code') && get(params, 'login')) { - // state match if (get(this, 'github').stateMatches(get(params, 'state'))) { let ghProvider = get(this, 'access.providers').findBy('id', 'github'); return ghProvider.doAction('login', { code: get(params, 'code'), responseType: 'cookie', }).then(() => { - debugger; - this.transitionTo('/'); + return this.transitionTo('authenticated'); + }).catch((err) => { + return this.transitionTo('login', {queryParams: {errorMsg: err.statusText, errorCode: err.status}}); }); } // return get(this, 'globalStore').request({ diff --git a/lib/global-admin/addon/security/authentication/github/template.hbs b/lib/global-admin/addon/security/authentication/github/template.hbs index 32cce1c90..4f7b4842b 100644 --- a/lib/global-admin/addon/security/authentication/github/template.hbs +++ b/lib/global-admin/addon/security/authentication/github/template.hbs @@ -28,7 +28,7 @@ - diff --git a/lib/shared/addon/github/service.js b/lib/shared/addon/github/service.js index 73488799c..e1270db32 100644 --- a/lib/shared/addon/github/service.js +++ b/lib/shared/addon/github/service.js @@ -68,12 +68,24 @@ export default Service.extend({ }); }, + getAuthorizeUrl(auth, state) { + var url = Util.addQueryParams(get(auth, 'redirectUrl'), { + redirect_uri: `${window.location.origin}/verify-auth`, + authProvider: 'github', + state: state, + scope: 'read:org' + }); + + return window.location.href = url; + }, + getGithubAuthUrl() { let provider = get(this, 'access.providers').findBy('id', 'github'); let authRedirect = get(provider, 'redirectUrl'); - let redirect = get(this, 'session').get(C.SESSION.BACK_TO) || `${window.location.origin}/verify-auth?login=true`; + let redirect = `${window.location.origin}/verify-auth`; var url = Util.addQueryParams(authRedirect, { + login: true, redirect_uri: redirect, state: this.generateState(), }); @@ -85,26 +97,6 @@ export default Service.extend({ window.location.href = this.getGithubAuthUrl(); }, - getAuthorizeUrl: function() { - // var redirect = get(this, 'session').get(C.SESSION.BACK_TO) || window.location.href; - - // if ( test ) - // { - // redirect = Util.addQueryParam(redirect, 'isTest', 1); - // } - - // var url = Util.addQueryParams(get(this, 'access.token.redirectUrl'), { - // state: this.generateState(), - // redirect_uri: redirect - // }); - - // return url; - }, - - authorizeRedirect: function() { - window.location.href = this.getAuthorizeUrl(); - }, - authorizeTest: function(config, cb) { var responded = false; window.onGithubTest = (err,code) => { @@ -117,7 +109,12 @@ export default Service.extend({ }; set(this, 'state', this.generateState()); - var popup = window.open(`${window.location.origin}/verify-auth?config=github`, 'rancherAuth', Util.popupWindowOptions()); + + let url = Util.addQueryParams(`${window.location.origin}/verify-auth`, { + config: 'github', + }); + + var popup = window.open(url, 'rancherAuth', Util.popupWindowOptions()); var timer = setInterval(function() { if ( !popup || popup.closed ) { clearInterval(timer);