-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3669be2
commit cb65e72
Showing
27 changed files
with
1,136 additions
and
98 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 |
---|---|---|
@@ -1,39 +1,55 @@ | ||
/* eslint-disable prettier/prettier, ember/no-get */ | ||
/* eslint-disable ember/no-get */ | ||
import IreneAuth from './irene'; | ||
import ENV from 'irene/config/environment'; | ||
import { Promise } from 'rsvp'; | ||
import { getOwner } from '@ember/application'; | ||
|
||
const b64EncodeUnicode = str => btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode(`0x${p1}`))); | ||
const b64EncodeUnicode = (str) => | ||
btoa( | ||
encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => | ||
String.fromCharCode(`0x${p1}`) | ||
) | ||
); | ||
|
||
const getB64Token = (user, token) => b64EncodeUnicode(`${user}:${token}`); | ||
|
||
const processData = data => { | ||
const processData = (data) => { | ||
data.b64token = getB64Token(data.user_id, data.token); | ||
|
||
return data; | ||
}; | ||
|
||
export default IreneAuth.extend({ | ||
authenticate(ssotoken) { | ||
return new Promise((resolve, reject) => { | ||
const url = ENV['endpoints']['saml2Login']; | ||
this.get("ajax").post( | ||
url, { data: {token: ssotoken}} | ||
).then((data) => { | ||
data = processData(data); | ||
resolve(data); | ||
this.resumeTransistion(); | ||
}, (error) => { | ||
let msg = "Login failed"; | ||
if(error.payload.message) { | ||
msg = "Login failed: " + error.payload.message; | ||
} | ||
this.get("notify").error(msg); | ||
|
||
const authenticatedRoute = getOwner(this).lookup("route:authenticated"); | ||
authenticatedRoute.transitionTo('login'); | ||
return reject(msg); | ||
}); | ||
|
||
this.get('ajax') | ||
.post(url, { data: { token: ssotoken } }) | ||
.then( | ||
(data) => { | ||
data = processData(data); | ||
|
||
resolve(data); | ||
}, | ||
(error) => { | ||
let msg = 'Login failed'; | ||
|
||
if (error.payload.message) { | ||
msg = 'Login failed: ' + error.payload.message; | ||
} | ||
|
||
this.get('notify').error(msg); | ||
|
||
const authenticatedRoute = getOwner(this).lookup( | ||
'route:authenticated' | ||
); | ||
|
||
authenticatedRoute.transitionTo('login'); | ||
|
||
return reject(msg); | ||
} | ||
); | ||
}); | ||
} | ||
}, | ||
}); |
Oops, something went wrong.