github urls

This commit is contained in:
Westly Wright 2018-02-16 14:33:27 -07:00
parent 450cc432c1
commit 5cbba00899
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
3 changed files with 25 additions and 28 deletions

View File

@ -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({

View File

@ -28,7 +28,7 @@
<button class="btn btn-sm right-divider-btn" {{action "promptDisable"}} disabled=true>
{{t 'generic.edit'}}
</button>
<button class="btn btn-sm right-divider-btn bg-error" {{action "promptDisable"}}>
<button class="btn btn-sm right-divider-btn bg-error" {{action "disable"}}>
{{t 'authPage.github.authenticated.disableAccess.disable'}}
</button>
</div>

View File

@ -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);