diff --git a/lib/login/addon/components/login-ping/component.js b/lib/login/addon/components/login-ping/component.js new file mode 100644 index 000000000..1a2fdc0d6 --- /dev/null +++ b/lib/login/addon/components/login-ping/component.js @@ -0,0 +1,16 @@ +import { inject as service } from '@ember/service'; +import Component from '@ember/component'; +import { get, set } from '@ember/object'; + +export default Component.extend({ + saml: service(), + errors: null, + + actions: { + authenticate() { + get(this, 'saml').login().catch( ( err ) => { + set(this, 'errors', [err.message]) + }); + } + } +}); diff --git a/lib/login/addon/components/login-ping/template.hbs b/lib/login/addon/components/login-ping/template.hbs new file mode 100644 index 000000000..e2f752d95 --- /dev/null +++ b/lib/login/addon/components/login-ping/template.hbs @@ -0,0 +1,6 @@ +
+ + {{top-errors errors=errors}} +
diff --git a/lib/login/addon/login/controller.js b/lib/login/addon/login/controller.js index bfade3cb9..e06f8187b 100644 --- a/lib/login/addon/login/controller.js +++ b/lib/login/addon/login/controller.js @@ -131,6 +131,10 @@ export default Controller.extend({ return !!get(this, 'access.providers').findBy('id', 'github'); }), + isPing: computed('access.providers', function() { + return !!get(this, 'access.providers').findBy('id', 'ping'); + }), + isActiveDirectory: computed('access.provider', function() { return !!get(this, 'access.providers').findBy('id', 'activedirectory'); }), diff --git a/lib/login/addon/login/template.hbs b/lib/login/addon/login/template.hbs index 702525a48..b33a933ba 100644 --- a/lib/login/addon/login/template.hbs +++ b/lib/login/addon/login/template.hbs @@ -60,6 +60,10 @@ {{login-azure action="started"}} {{/if}} + {{#if isPing}} + {{login-ping action="started"}} + {{/if}} + {{#if isLocal}} {{login-user-pass action="authenticate" diff --git a/lib/shared/addon/saml/service.js b/lib/shared/addon/saml/service.js index 3d0467b61..a0b79a0fe 100644 --- a/lib/shared/addon/saml/service.js +++ b/lib/shared/addon/saml/service.js @@ -8,13 +8,25 @@ export default Service.extend({ access: service(), app: service(), - test(config, cb) { + login() { + const finalUrl = window.location.origin; + const provider = get(this, 'access.providers').findBy('id', 'ping'); + return provider.doAction('login', { finalRedirectUrl: finalUrl }).then( ( resp ) => { + return window.location.href = resp.idpRedirectUrl; + }).catch(() => { + return { + type: 'error', + message: get(this, 'intl').t('authPage.saml.authError') + } + }); + }, + + test(config, cb) { let responded = false; window.onAuthTest = (err, code) => { if ( !responded ) { - let authConfig = code; responded = true; @@ -28,7 +40,6 @@ export default Service.extend({ let timer = setInterval(function() { if (popup && popup.closed ) { - clearInterval(timer); if ( !responded ) { @@ -52,11 +63,9 @@ export default Service.extend({ } } }, 500); - }, finishTest(config, code, cb) { - const authConfig = config; set(authConfig, 'enabled', true); @@ -64,16 +73,13 @@ export default Service.extend({ const allowedPrincipalIds = get(authConfig, 'allowedPrincipalIds') || []; return authConfig.save().then(() => { - let found = false; const myPIds = get(this, 'access.me.principalIds'); myPIds.forEach( (id) => { - if (allowedPrincipalIds.indexOf(id) >= 0) { found = true; } - }); if ( !found && !allowedPrincipalIds.length) { @@ -83,7 +89,6 @@ export default Service.extend({ return authConfig.save().then(() => { window.location.href = window.location.href; }); - }).catch((err) => { cb(err); }); diff --git a/translations/en-us.yaml b/translations/en-us.yaml index 0b7390522..3bd9a4a67 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -377,7 +377,7 @@ authPage: post: 'Waiting to hear back from Ping' providerName: ping: Ping - authError: 'Github access was not authorized' + authError: 'Access was not authorized' popupError: 'Please disable your pop-up blocker and click "Authenticate" again.' shibboleth: @@ -4190,6 +4190,9 @@ loginGithub: loginAzure: buttonText: Log In with Azure AD +loginPing: + buttonText: Log In with Ping Federate + loginUserPass: local: Use a Local User provider: "{kind}"