From cb55194031d01efef0a1c13c14ad9672125d115a Mon Sep 17 00:00:00 2001 From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Wed, 10 Mar 2021 07:55:37 -0700 Subject: [PATCH] pr feedback --- app/verify-auth-azure/route.js | 2 +- app/verify/route.js | 5 +- lib/shared/addon/azure-ad/service.js | 52 ++------------------- lib/shared/addon/pipeline-github/service.js | 23 +-------- 4 files changed, 9 insertions(+), 73 deletions(-) diff --git a/app/verify-auth-azure/route.js b/app/verify-auth-azure/route.js index 97448cea2..076a4eabd 100644 --- a/app/verify-auth-azure/route.js +++ b/app/verify-auth-azure/route.js @@ -1,7 +1,7 @@ import Route from '@ember/routing/route'; export default Route.extend( { - model() { + beforeModel() { this.transitionTo('verify'); } }); \ No newline at end of file diff --git a/app/verify/route.js b/app/verify/route.js index 0424d0531..0b94d592d 100644 --- a/app/verify/route.js +++ b/app/verify/route.js @@ -117,9 +117,6 @@ export default Route.extend(VerifyAuth, { if ( get(params, 'code') ) { let openers = openersOauth - if (parsedState.provider === 'azuread'){ - openers = openersAzure - } if ( openers.stateMatches(get(parsedState, 'nonce')) ) { reply(params.error_description, params.code); } else { @@ -143,7 +140,7 @@ export default Route.extend(VerifyAuth, { } catch { reply({ err: 'nonce' }) } - if (oauth.stateMatches(parsedState.nonce) || (parsedState.provider === 'azuread' && azure.stateMatches(parsedState.nonce))){ + if (oauth.stateMatches(parsedState.nonce)){ const providerType = parsedState.provider const currentProvider = get(this, 'access.providers').findBy('id', providerType); diff --git a/lib/shared/addon/azure-ad/service.js b/lib/shared/addon/azure-ad/service.js index b6e052cdf..7d79d15e5 100644 --- a/lib/shared/addon/azure-ad/service.js +++ b/lib/shared/addon/azure-ad/service.js @@ -15,51 +15,7 @@ export default Service.extend({ globalStore: service(), app: service(), intl: service(), - - generateState() { - const state = JSON.stringify({ - to: 'ember', - provider: 'azuread', - nonce: Math.random(), - test: true - }) - - - return set(this, 'session.oauthState', state); - }, - - generateLoginStateKey() { - const state = JSON.stringify({ - to: 'ember', - provider: 'azuread', - nonce: Math.random(), - test: false - }) - - return set(this, 'session.oauthState', state); - }, - - encodeState(state){ - const m = { - '+': '-', - '/': '_', - '=': '' - } - - return AWS.util.base64.encode(state).replace(/[+/]|=$/, (char) => m[char]) - }, - - stateMatches(actual) { - const state = get(this, 'session.oauthState') - - try { - const parsedState = JSON.parse(state) - - return actual && actual === parsedState.nonce - } catch { - return false - } - }, + oauth: service(), testConfig(config) { return config.doAction('configureTest', config); @@ -74,7 +30,7 @@ export default Service.extend({ const authRedirect = get(provider, 'redirectUrl'); let redirect = Util.addQueryParams(authRedirect, additionalRedirectParams); - redirect = Util.addQueryParams(redirect, { state: this.encodeState(this.generateState()) }); + redirect = Util.addQueryParams(redirect, { state: this.oauth.encodeState(this.oauth.generateState('azuread')) }); window.location.href = redirect; @@ -94,7 +50,9 @@ export default Service.extend({ }; url = Util.addQueryParams(url, additionalRedirectParams); - url = Util.addQueryParams(url, { state: this.encodeState(this.generateState()) }); + const state = this.oauth.encodeState(this.oauth.generateState('azuread')) + + url = Util.addQueryParams(url, { state }); const popup = window.open(url, 'rancherAuth', Util.popupWindowOptions()); diff --git a/lib/shared/addon/pipeline-github/service.js b/lib/shared/addon/pipeline-github/service.js index 002ce74d3..ab51252f3 100644 --- a/lib/shared/addon/pipeline-github/service.js +++ b/lib/shared/addon/pipeline-github/service.js @@ -10,27 +10,8 @@ export default Service.extend({ hostname: null, scheme: null, clientId: null, + oauth: service(), - generateState() { - const state = JSON.stringify({ - to: 'ember', - provider: 'github', - nonce: Math.random(), - test: true - }) - - return set(this, 'session.oauthState', state); - }, - - encodeState(state){ - const m = { - '+': '-', - '/': '_', - '=': '' - } - - return AWS.util.base64.encode(state).replace(/[+/]|=$/, (char) => m[char]) - }, redirectURL: computed(() => { @@ -42,7 +23,7 @@ export default Service.extend({ redirect = redirect.split('#')[0]; var url = Util.addQueryParams(githubAuthUrl, { - state: this.encodeState(this.generateState()), + state: this.oauth.encodeState(this.oauth.generateState('github')), redirect_uri: redirect });