Skip to content

Commit

Permalink
auth method change and start for ghc package
Browse files Browse the repository at this point in the history
  • Loading branch information
birm committed Apr 17, 2019
1 parent b68719c commit cf7617d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 48 deletions.
68 changes: 47 additions & 21 deletions login.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<html>
<script async defer src="https://apis.google.com/js/platform.js?onload=handleClientLoad"></script>
<h1>Redirecting...</h1>
<script>
// config vars, these are DEFAULTS
var audience = "wolf.cci.emory.edu/camic_uat"
var scope = "openid%20email"
var client_id = "YLRDUmEs5Jivi6FX3XtNNAt97X3a0epD"
// GHC specific
var GHC_CLIENT_ID = 'INSERT-YOUR-CLIENT-ID-HERE'
// handle urls automatically
var base_deployment_url = window.location.toString().split("/").slice(0,-1).join("/")
var redirect_uri = base_deployment_url + "/login.html"
Expand Down Expand Up @@ -47,29 +50,52 @@ <h1>Redirecting...</h1>
if (!state){
state = default_redirect
}
// is this a login pre or post?
if (id_token){
document.cookie = cookie_name + "=" + id_token;
fetch("./auth/Token/check",
{headers: {
'Authorization': "Bearer " + id_token
}}
).then(x=>x.json()).then(x=>{
console.log("{id provider", id_token)
console.log("{auth service}", x)
if (x.hasOwnProperty('token')){
document.cookie = cookie_name + "=" + x.token;
window.location = state
} else {
console.error("please give me a better failure message/response")
}
// is this a GHC login?
if(getUrlParam("mode") == "GHC"){
const CLOUD_HEALTHCARE_API_BASE =
'https://healthcare.googleapis.com/v1beta1/projects/';
const SCOPE = 'https://www.googleapis.com/auth/cloud-healthcare';
const STUDIES_PATH = '/studies';
const SERIES_PATH = '/series';
gapi.auth2.init({'clientId': GHC_CLIENT_ID, 'scope': SCOPE})
.then(
function() {
googleAuth = gapi.auth2.getAuthInstance();

if (googleAuth == null) {
alert(
`GHC Login failed.`);
return;
}
document.cookie = "GhcToken=" googleAuth.currentUser.get().getAuthResponse(true).access_token;
window.location = state;
});

})
} else {
window.localStorage.setItem('nonce', randomString(16));
auth_url += "&state=" + state
auth_url += "&nonce=" + window.localStorage.getItem('nonce')
window.location = auth_url
// is this a login pre or post?
if (id_token){
document.cookie = cookie_name + "=" + id_token;
fetch("./auth/Token/check",
{headers: {
'Authorization': "Bearer " + id_token
}}
).then(x=>x.json()).then(x=>{
console.log("{id provider", id_token)
console.log("{auth service}", x)
if (x.hasOwnProperty('token')){
document.cookie = cookie_name + "=" + x.token;
window.location = state
} else {
console.error("please give me a better failure message/response")
}

})
} else {
window.localStorage.setItem('nonce', randomString(16));
auth_url += "&state=" + state
auth_url += "&nonce=" + window.localStorage.getItem('nonce')
window.location = auth_url
}
}
</script>
<html>
27 changes: 0 additions & 27 deletions package/GhcAuth.js

This file was deleted.

40 changes: 40 additions & 0 deletions package/ghc_package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// this is not working yet. WIP until I can look at the data
CaMic.prototype.loadImg = function(func) {
// do we have a GHC token?
// load up!
var img_id = urlParams.get('id');
this.slideId = slideId
this.slideName = slideId
this.study = ""
this.specimen = ""

this.mpp = 1e9;
this.mpp_x = this.mpp;
this.mpp_y = this.mpp;
// TODO what to do about this
var ghc_source = {
height: maxHeightPx,
width: maxWidthPx,
tileSize: tileWidthPx,
maxLevel: countLevels - 1,
minLevel: 0,
getTileUrl: function(level, row, col) {
const x = 1 + (tileWidthPx * row);
const y = 1 + (tileHeightPx * col);
const z = countLevels - 1 - level;
const key = x + '/' + y + '/' + z;
const params = pyramidMeta[key];
return toDicomWebWADOUrl(
instancesPath + '/' + params.SOPInstanceUID + '/frames/' +
params.FrameNumber + '/rendered');
},
getLevelScale: function(level) {
return sortedLevelWidths[countLevels - 1 - level] / maxWidthPx;
}
};
this.viewer.open(ghc_source);

if (func && typeof func === 'function') {
func.call(null, x);
}
}

0 comments on commit cf7617d

Please sign in to comment.