-
Notifications
You must be signed in to change notification settings - Fork 15
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
Showing
5 changed files
with
71 additions
and
157 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
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,138 +1,19 @@ | ||
<script src="openseadragon121/openseadragon.min.js"></script> | ||
<html> | ||
<head> | ||
<title>IIIF Auth Test</title> | ||
<script src="openseadragon200/openseadragon.min.js"></script> | ||
<script src="jquery-1.11.1.min.js"></script> | ||
<script src="iiif-auth-092.1.js"></script> | ||
|
||
<h2>IIIF OpenSeadragon Authentication Test</h2> | ||
|
||
<div id="container" style="width: 605px; height: 405px;"></div> | ||
<div id="authbox" style="margin-top: 10px; height: 3ex; border: 2px solid green; width: 605px;"></div> | ||
<div id="log" style="margin-top: 10px; height: 20ex; border: 2px solid green; width: 605px; overflow: auto;"></div> | ||
<script src="iiif-auth-092.js"></script> | ||
<head> | ||
<body> | ||
<h2>IIIF OpenSeadragon Basic Authentication Test</h2> | ||
|
||
<div id="demo">Loading demo...</div> | ||
<script type="text/javascript"> | ||
var base_uri="http://localhost:8001/2.1_pil_basic"; | ||
var linenum=0; | ||
function log(text) { | ||
linenum=linenum+1 | ||
$('#log').prepend("[" + linenum + "] " + text + "<br>"); | ||
} | ||
|
||
// check for an auth service ... once tileSource has loaded | ||
function on_authed() { | ||
// first try to get an authorization token from the token service ... | ||
// via JSONP :( | ||
// XXX TODO: get the URL from the info.json | ||
log("Fetching Token"); | ||
$.getJSON(base_uri+"/token?callback=?", on_tokened); | ||
} | ||
|
||
|
||
function on_tokened(data) { | ||
|
||
var token, error; | ||
if (data.hasOwnProperty('access_token')) { | ||
token = data.access_token; | ||
error = false; | ||
log("Got token: " + token); | ||
} else { | ||
// error condition | ||
token = ''; | ||
error = true; | ||
log("Got error: " + data.error) | ||
} | ||
|
||
if (error) { | ||
// Error make unauthed viewer | ||
make_viewer(); | ||
} else { | ||
// Okay, make authed viewer | ||
$('#openseadragon').remove(); | ||
$('#authbox').empty(); | ||
$('#container').append('<div id="openseadragon" style="width: 600px; height: 400px; border: 2px solid purple" ></div>'); | ||
$.ajax({ url:base_uri+"/starfish/info.json", headers: {"Authorization":token}, cache: false, success: on_got_info }); | ||
} | ||
} | ||
|
||
function on_got_info(data) { | ||
|
||
log("Got full info.json") | ||
|
||
process_auth_services(data, 'logout'); | ||
|
||
viewer = OpenSeadragon({ | ||
id: "openseadragon", | ||
tileSources: data, | ||
showNavigator: true, | ||
prefixUrl: "openseadragon121/images/" | ||
}); | ||
} | ||
|
||
function do_auth(evt) { | ||
login = $(this).attr('data-login'); | ||
|
||
// The redirected to window will self-close | ||
// open/closed state is the only thing we can see across domains :( | ||
log("Opening Auth service"); | ||
var win = window.open(login, 'loginwindow'); | ||
var pollTimer = window.setInterval(function() { | ||
if (win.closed) { | ||
window.clearInterval(pollTimer); | ||
on_authed(); | ||
} | ||
}, 500); | ||
} | ||
|
||
function process_auth_services(info, which) { | ||
log("Looking for "+which+" service") | ||
if (info.hasOwnProperty('service')) { | ||
if (info.service.hasOwnProperty('@id')) { | ||
services = [info.service] | ||
} else { | ||
// array of service | ||
services = info.service | ||
} | ||
for (var service,i=0;service=services[i];i++) { | ||
if (service['profile'] == 'http://iiif.io/api/auth/0/'+which) { | ||
log("Found "+which+" auth service"); | ||
login = service['@id']; | ||
$('#authbox').append("<button id='authbutton' data-login='"+login+"'>"+service.label+"</button>"); | ||
$('#authbutton').bind('click', do_auth); | ||
} else if (which == 'login' && service['profile'] == 'http://iiif.io/api/auth/0/token') { | ||
// save token service here... | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
function handle_open(event) { | ||
var info = event.eventSource.source; | ||
// This only gets called when we're NOT authed, so no need to put in logout | ||
process_auth_services(info, 'login'); | ||
} | ||
|
||
function make_viewer() { | ||
|
||
log("Making unauthed viewer"); | ||
|
||
$('#openseadragon').remove(); | ||
$('#authbox').empty(); | ||
$('#container').append('<div id="openseadragon" style="width: 600px; height: 400px; border: 2px solid purple" ></div>'); | ||
var where = $("#openseadragon"); | ||
|
||
var viewer = OpenSeadragon({ | ||
id: "openseadragon", | ||
tileSources: base_uri+"/starfish/info.json?t=" + new Date().getTime(), | ||
showNavigator: true, | ||
prefixUrl: "openseadragon121/images/" | ||
}); | ||
|
||
viewer.addHandler('open', handle_open) | ||
viewer.addHandler('failed-open', handle_open) | ||
} | ||
|
||
// Start with an unauthed viewer | ||
make_viewer() | ||
// Start with a viewer which will be unauthenticated initially | ||
iiif_auth.make_demo_page("http://localhost:8001/2.1_pil_basic/tetons"); | ||
</script> | ||
|
||
</body> | ||
</html> | ||
|
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,24 +1,18 @@ | ||
<html> | ||
<head> | ||
<title>IIIF Auth Tests</title> | ||
<script src="openseadragon121/openseadragon.min.js"></script> | ||
<title>IIIF Auth Test</title> | ||
<script src="openseadragon200/openseadragon.min.js"></script> | ||
<script src="jquery-1.11.1.min.js"></script> | ||
<script src="iiif-auth-092.1.js"></script> | ||
<script src="iiif-auth-092.js"></script> | ||
<head> | ||
<body> | ||
<h2>IIIF OpenSeadragon Authentication Test</h2> | ||
|
||
<div id="container" style="width: 605px; height: 405px;"></div> | ||
<div id="authbox" style="margin-top: 10px; height: 3ex; border: 2px solid red; width: 605px;"></div> | ||
<div id="log" style="margin-top: 10px; height: 20ex; border: 2px solid green; width: 605px; overflow: auto;"></div> | ||
<iframe id="messageFrame" style="margin-top: 10px; height: 3ex; border: 2px solid blue; width: 605px;"></iframe> | ||
<h2>IIIF OpenSeadragon Google Authentication Test</h2> | ||
|
||
<div id="demo">Loading demo...</div> | ||
<script type="text/javascript"> | ||
// Start with a viewer which be unauthed initially | ||
iiif_auth.make_viewer("http://localhost:8001/2.1_pil_gauth/tetons"); | ||
// Start with a viewer which will be unauthenticated initially | ||
iiif_auth.make_demo_page("http://localhost:8001/2.1_pil_gauth/tetons"); | ||
</script> | ||
|
||
<p>Relies upon image server with Google auth at <code><a href="http://localhost:8001/2.1_pil_gauth/tetons">http://localhost:8001/2.1_pil_gauth/tetons</a></code>.</p> | ||
|
||
</body> | ||
</html> |