-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: Model Layer for SSO Support (#7771)
* ui: Adds model layer required for SSO 1. oidc-provider ember-data triplet plus repo, plus addition of torii addon 2. Make blocking queries support a Cache-Control: no-cache header 3. Tweaks to the token model layer in preparation for SSO work * Fix up meta related Cache-Control tests * Add tests adapter tests for URL shapes * Reset Cache-Control to the original value, return something from logout
- Loading branch information
Showing
24 changed files
with
434 additions
and
35 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
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,97 @@ | ||
import Adapter from './application'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
import { env } from 'consul-ui/env'; | ||
import nonEmptySet from 'consul-ui/utils/non-empty-set'; | ||
|
||
let Namespace; | ||
if (env('CONSUL_NSPACES_ENABLED')) { | ||
Namespace = nonEmptySet('Namespace'); | ||
} else { | ||
Namespace = () => ({}); | ||
} | ||
export default Adapter.extend({ | ||
env: service('env'), | ||
requestForQuery: function(request, { dc, ns, index }) { | ||
return request` | ||
GET /v1/internal/ui/oidc-auth-methods?${{ dc }} | ||
${{ | ||
index, | ||
...this.formatNspace(ns), | ||
}} | ||
`; | ||
}, | ||
requestForQueryRecord: function(request, { dc, ns, id }) { | ||
if (typeof id === 'undefined') { | ||
throw new Error('You must specify an id'); | ||
} | ||
return request` | ||
POST /v1/acl/oidc/auth-url?${{ dc }} | ||
Cache-Control: no-store | ||
${{ | ||
...Namespace(ns), | ||
AuthMethod: id, | ||
RedirectURI: `${this.env.var('CONSUL_BASE_UI_URL')}/torii/redirect.html`, | ||
}} | ||
`; | ||
}, | ||
requestForAuthorize: function(request, { dc, ns, id, code, state }) { | ||
if (typeof id === 'undefined') { | ||
throw new Error('You must specify an id'); | ||
} | ||
if (typeof code === 'undefined') { | ||
throw new Error('You must specify an code'); | ||
} | ||
if (typeof state === 'undefined') { | ||
throw new Error('You must specify an state'); | ||
} | ||
return request` | ||
POST /v1/acl/oidc/callback?${{ dc }} | ||
Cache-Control: no-store | ||
${{ | ||
...Namespace(ns), | ||
AuthMethod: id, | ||
Code: code, | ||
State: state, | ||
}} | ||
`; | ||
}, | ||
requestForLogout: function(request, { id }) { | ||
if (typeof id === 'undefined') { | ||
throw new Error('You must specify an id'); | ||
} | ||
return request` | ||
POST /v1/acl/logout | ||
Cache-Control: no-store | ||
X-Consul-Token: ${id} | ||
`; | ||
}, | ||
authorize: function(store, type, id, snapshot) { | ||
return this.request( | ||
function(adapter, request, serialized, unserialized) { | ||
return adapter.requestForAuthorize(request, serialized, unserialized); | ||
}, | ||
function(serializer, respond, serialized, unserialized) { | ||
return serializer.respondForAuthorize(respond, serialized, unserialized); | ||
}, | ||
snapshot, | ||
type.modelName | ||
); | ||
}, | ||
logout: function(store, type, id, snapshot) { | ||
return this.request( | ||
function(adapter, request, serialized, unserialized) { | ||
return adapter.requestForLogout(request, serialized, unserialized); | ||
}, | ||
function(serializer, respond, serialized, unserialized) { | ||
// its ok to return nothing here for the moment at least | ||
return {}; | ||
}, | ||
snapshot, | ||
type.modelName | ||
); | ||
}, | ||
}); |
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,37 @@ | ||
import Oauth2CodeProvider from 'torii/providers/oauth2-code'; | ||
const NAME = 'oidc-with-url'; | ||
const Provider = Oauth2CodeProvider.extend({ | ||
name: NAME, | ||
buildUrl: function() { | ||
return this.baseUrl; | ||
}, | ||
open: function(options) { | ||
const name = this.get('name'), | ||
url = this.buildUrl(), | ||
responseParams = ['state', 'code'], | ||
responseType = 'code'; | ||
return this.get('popup') | ||
.open(url, responseParams, options) | ||
.then(function(authData) { | ||
// the same as the parent class but with an authorizationState added | ||
return { | ||
authorizationState: authData.state, | ||
authorizationCode: decodeURIComponent(authData[responseType]), | ||
provider: name, | ||
}; | ||
}); | ||
}, | ||
close: function() { | ||
const popup = this.get('popup.remote') || {}; | ||
if (typeof popup.close === 'function') { | ||
return popup.close(); | ||
} | ||
}, | ||
}); | ||
export function initialize(application) { | ||
application.register(`torii-provider:${NAME}`, Provider); | ||
} | ||
|
||
export default { | ||
initialize, | ||
}; |
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,15 @@ | ||
import Model from 'ember-data/model'; | ||
import attr from 'ember-data/attr'; | ||
|
||
export const PRIMARY_KEY = 'uid'; | ||
export const SLUG_KEY = 'Name'; | ||
export default Model.extend({ | ||
[PRIMARY_KEY]: attr('string'), | ||
[SLUG_KEY]: attr('string'), | ||
meta: attr(), | ||
Datacenter: attr('string'), | ||
DisplayName: attr('string'), | ||
Kind: attr('string'), | ||
Namespace: attr('string'), | ||
AuthURL: attr('string'), | ||
}); |
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,30 @@ | ||
import Serializer from './application'; | ||
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/oidc-provider'; | ||
|
||
export default Serializer.extend({ | ||
primaryKey: PRIMARY_KEY, | ||
slugKey: SLUG_KEY, | ||
respondForAuthorize: function(respond, serialized, data) { | ||
// we avoid the parent serializer here as it tries to create a | ||
// fingerprint for an 'action' request | ||
// but we still need to pass the headers through | ||
return respond((headers, body) => { | ||
return this.attachHeaders(headers, body, data); | ||
}); | ||
}, | ||
respondForQueryRecord: function(respond, query) { | ||
// add the name and nspace here so we can merge this | ||
// TODO: Look to see if we always want the merging functionality | ||
return this._super( | ||
cb => | ||
respond((headers, body) => | ||
cb(headers, { | ||
Name: query.id, | ||
Namespace: query.ns, | ||
...body, | ||
}) | ||
), | ||
query | ||
); | ||
}, | ||
}); |
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
Oops, something went wrong.