-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SSO] Auth Methods and Mock OIDC Flow (#15155)
* Big ol first pass at a redirect sign in flow * dont recursively add queryparams on redirect * Passing state and code qps * In which I go off the deep end and embed a faux provider page in the nomad ui * Buggy but self-contained flow * Flow auto-delay added and a little more polish to resetting token * secret passing turned to accessor passing * Handle SSO Failure * General cleanup and test fix * Lintfix * SSO flow acceptance tests * Percy snapshots added * Explicitly note the OIDC test route is mirage only * Handling failure case for complete-auth * Leentfeex
- Loading branch information
1 parent
f141acb
commit 4dc2421
Showing
17 changed files
with
521 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// @ts-check | ||
import { default as ApplicationAdapter, namespace } from './application'; | ||
import { dasherize } from '@ember/string'; | ||
import classic from 'ember-classic-decorator'; | ||
|
||
@classic | ||
export default class AuthMethodAdapter extends ApplicationAdapter { | ||
namespace = `${namespace}/acl`; | ||
|
||
/** | ||
* @param {string} modelName | ||
* @returns {string} | ||
*/ | ||
urlForFindAll(modelName) { | ||
return dasherize(this.buildURL(modelName)); | ||
} | ||
|
||
/** | ||
* @typedef {Object} ACLOIDCAuthURLParams | ||
* @property {string} AuthMethod | ||
* @property {string} RedirectUri | ||
* @property {string} ClientNonce | ||
* @property {Object[]} Meta // NOTE: unsure if array of objects or kv pairs | ||
*/ | ||
|
||
/** | ||
* @param {ACLOIDCAuthURLParams} params | ||
* @returns | ||
*/ | ||
getAuthURL({ AuthMethod, RedirectUri, ClientNonce, Meta }) { | ||
const url = `/${this.namespace}/oidc/auth-url`; | ||
return this.ajax(url, 'POST', { | ||
data: { | ||
AuthMethod, | ||
RedirectUri, | ||
ClientNonce, | ||
Meta, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Controller from '@ember/controller'; | ||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
import Ember from 'ember'; | ||
|
||
export default class OidcMockController extends Controller { | ||
@service router; | ||
|
||
queryParams = ['auth_method', 'client_nonce', 'redirect_uri', 'meta']; | ||
|
||
@action | ||
signIn(fakeAccount) { | ||
const url = `${this.redirect_uri.split('?')[0]}?code=${ | ||
fakeAccount.accessor | ||
}&state=success`; | ||
if (Ember.testing) { | ||
this.router.transitionTo(url); | ||
} else { | ||
window.location = url; | ||
} | ||
} | ||
|
||
@action | ||
failToSignIn() { | ||
const url = `${this.redirect_uri.split('?')[0]}?state=failure`; | ||
if (Ember.testing) { | ||
this.router.transitionTo(url); | ||
} else { | ||
window.location = url; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @ts-check | ||
import Model from '@ember-data/model'; | ||
import { attr } from '@ember-data/model'; | ||
|
||
export default class AuthMethodModel extends Model { | ||
@attr('string') name; | ||
@attr('string') type; | ||
@attr('string') tokenLocality; | ||
@attr('string') maxTokenTTL; | ||
@attr('boolean') default; | ||
@attr('date') createTime; | ||
@attr('number') createIndex; | ||
@attr('date') modifyTime; | ||
@attr('number') modifyIndex; | ||
|
||
getAuthURL(params) { | ||
return this.store.adapterFor('authMethod').getAuthURL(params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default class OidcMockRoute extends Route { | ||
// This route only exists for testing SSO/OIDC flow in development, backed by our mirage server. | ||
// This route won't load outside of a mirage environment, nor will the model hook here return anything meaningful. | ||
model() { | ||
return this.store.findAll('token'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// @ts-check | ||
import Route from '@ember/routing/route'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default class SettingsTokensRoute extends Route { | ||
@service store; | ||
model() { | ||
return { | ||
authMethods: this.store.findAll('auth-method'), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{page-title "Mock OIDC Test Page"}} | ||
|
||
<section class="mock-sso-provider"> | ||
<h1>OIDC Test route: {{this.auth_method}}</h1> | ||
<h2>(Mirage only)</h2> | ||
<div class="providers"> | ||
{{#each this.model as |fakeAccount|}} | ||
<button type="button" class="button" {{on "click" (fn this.signIn fakeAccount)}}> | ||
Sign In as {{fakeAccount.name}} | ||
</button> | ||
{{/each}} | ||
<button type="button" class="button error" {{on "click" this.failToSignIn}}> | ||
Simulate Failure | ||
</button> | ||
</div> | ||
</section> | ||
{{outlet}} |
Oops, something went wrong.