Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a custom authenticator for shibboleth #792

Merged
merged 2 commits into from
Jul 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions app/authenticators/ilios-jwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Ember from 'ember';
import JwtTokenAuthenticator from 'simple-auth-token/authenticators/jwt';

export default JwtTokenAuthenticator.extend({
/**
Extend the JwtTokenAuthenticator to accept a token in liu of credentials
This allows authentication of an already existing session.
@method authenticate
@param {Object} options The credentials to authenticate the session with
@return {Ember.RSVP.Promise} A promise that resolves when an auth token is
successfully acquired from the server and rejects
otherwise
*/
authenticate: function(credentials) {
return new Ember.RSVP.Promise((resolve, reject) => {
if(this.tokenPropertyName in credentials){
let token = credentials[this.tokenPropertyName];
let tokenData = this.getTokenData(token);
let expiresAt = tokenData[this.tokenExpireName];
let response = {};
response[this.tokenPropertyName] = token;
response[this.tokenExpireName] = expiresAt;
this.scheduleAccessTokenRefresh(expiresAt, token);

resolve(this.getResponseData(response));
} else {
var data = this.getAuthenticateData(credentials);

this.makeRequest(this.serverTokenEndpoint, data).then(response => {
var self = this;
Ember.run(function() {
var token = response[self.tokenPropertyName],
tokenData = self.getTokenData(token),
expiresAt = tokenData[self.tokenExpireName],
tokenExpireData = {};

self.scheduleAccessTokenRefresh(expiresAt, token);

tokenExpireData[self.tokenExpireName] = expiresAt;

response = Ember.merge(response, tokenExpireData);

resolve(self.getResponseData(response));
});
}, function(xhr) {
Ember.run(function() {
reject(xhr.responseJSON || xhr.responseText);
});
});
}
});
}
});
2 changes: 1 addition & 1 deletion app/controllers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default Ember.Controller.extend({
actions: {
authenticate: function() {
let credentials = this.getProperties('identification', 'password');
let authenticator = 'simple-auth-authenticator:jwt';
let authenticator = 'authenticator:ilios-jwt';
this.set('errors', []);
this.get('session').authenticate(authenticator, credentials).then(() => {
let jwt = this.get('session').get('secure.jwt');
Expand Down
2 changes: 1 addition & 1 deletion app/routes/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default Ember.Route.extend(UnauthenticatedRouteMixin, {
}
window.location.replace(shibbolethLoginUrl);
} else {
let authenticator = 'simple-auth-authenticator:jwt';
let authenticator = 'authenticator:ilios-jwt';

this.get('session').authenticate(authenticator, {jwt: token.jwt}).then(() => {
let jwt = this.get('session').get('secure.jwt');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ember-cli-sauce": "^1.0.0",
"ember-cli-simple-auth": "^0.8.0",
"ember-cli-simple-auth-testing": "0.8.0",
"ember-cli-simple-auth-token": "jrjohnson/ember-cli-simple-auth-token#authbyjwt",
"ember-cli-simple-auth-token": "^0.7.3",
"ember-cli-tooltipster": "0.0.9",
"ember-cli-uglify": "^1.0.1",
"ember-data": "1.13.3",
Expand Down
12 changes: 6 additions & 6 deletions tests/acceptance/dashboard/calendar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ test('load day calendar', function(assert) {
});

test('click month day number and go to day', function(assert) {
let today = moment().hour(8);
let aDayInTheMonth = moment().startOf('month').add(12, 'days').hour(8);
server.create('userevent', {
name: 'today',
startDate: today.format(),
endDate: today.clone().add(1, 'hour').format()
name: 'start of month',
startDate: aDayInTheMonth.format(),
endDate: aDayInTheMonth.clone().add(1, 'hour').format()
});
visit('/dashboard?view=month');
andThen(function() {
let dayOfMonth = today.date();
let dayOfMonth = aDayInTheMonth.date();
let link = find('.day a').filter(function(){
return parseInt($(this).text()) === dayOfMonth;
}).eq(0);
click(link).then(()=>{
assert.equal(currentURL(), '/dashboard?date=' + today.format('YYYY-MM-DD') + '&view=day');
assert.equal(currentURL(), '/dashboard?date=' + aDayInTheMonth.format('YYYY-MM-DD') + '&view=day');
});
});
});
Expand Down