feat: 🎸 add token validation support to ui
This commit is contained in:
3 files changed
+26
-2
No files matched your search
@@ -43,6 +43,17 @@ export default class PasswordAuthenticator extends BasePasswordAuthenticator {
|
||||
return adapter.buildURL('scope', scopeID, options, 'findRecord');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an auth token validation URL used to check tokens on restoration.
|
||||
* @override
|
||||
* @param {string} tokenID
|
||||
* @return {string}
|
||||
*/
|
||||
buildTokenValidationEndpointURL(tokenID) {
|
||||
const adapter = this.store.adapterFor('auth-token');
|
||||
return adapter.buildURL('auth-token', tokenID, {}, 'findRecord');
|
||||
}
|
||||
|
||||
/**
|
||||
* Intercepts the authenticate response, if any, and assigns the returned
|
||||
* token to all future requests via `addTokenToAuthorization`.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import config from '../config/environment';
|
||||
import { authHandler, deauthHandler } from './route-handlers/auth';
|
||||
import { pickRandomStatusString } from './factories/session';
|
||||
//import { Response } from 'miragejs';
|
||||
import { Response } from 'miragejs';
|
||||
|
||||
export default function() {
|
||||
|
||||
@@ -326,6 +326,14 @@ export default function() {
|
||||
return session.update(updatedAttrs);
|
||||
});
|
||||
|
||||
// auth-tokens
|
||||
|
||||
this.get('/auth-tokens/:id', function () {
|
||||
// Set to 401 or 404 to simulate token invalidation, which will
|
||||
// cause the session to fail restoration and logout the user.
|
||||
return new Response(200);
|
||||
});
|
||||
|
||||
/* Uncomment the following line and the Response import above
|
||||
* Then change the response code to simulate error responses.
|
||||
* this.get('/scopes', () => new Response(505));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { Response } from 'miragejs';
|
||||
|
||||
module('Unit | Authenticator | password', function (hooks) {
|
||||
setupTest(hooks);
|
||||
@@ -25,7 +26,11 @@ module('Unit | Authenticator | password', function (hooks) {
|
||||
|
||||
test('it adds an authorization header to application adapter on restore', async function (assert) {
|
||||
assert.expect(1);
|
||||
authenticator.restore({ token: 'token1234' });
|
||||
const mockData = { id: 'token1234', token: 'token1234' };
|
||||
this.server.get(authenticator.buildTokenValidationEndpointURL(mockData.id), () => {
|
||||
return new Response(200);
|
||||
});
|
||||
authenticator.restore(mockData);
|
||||
assert.equal(applicationAdapter.headers.Authorization, 'Bearer token1234');
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user