Open spalt opened 8 years ago
Did you get this.adalService.acquireToken to work?
Sort of. It works, but is it the right way? No clue. I'm doing this:
let adlContext = (this.adalService as any).adalContext;
adalService.config.redirectUri = window.location.origin + '/processtoken.html';
this.adlContext.acquireToken(url, function (error, null) { });
this.timer = setInterval(() => {
var iframe = (document.getElementById("adalRenewFrame" + url) as any);
if (iframe) {
var idoc = iframe.contentDocument || iframe.contentWindow.document;
if (iframe.src != '' && idoc.readyState == 'complete' && idoc.getElementById("access_token") && idoc.getElementById("access_token").innerHTML != '') {
clearInterval(this.timer);
this.adlContext._saveItem("access_token", idoc.getElementById("access_token").innerHTML);
}
}}, 100);
Note the "processtoken.html". You're telling azure to send a new token, and then on the return, hit it, which decodes the token from the query string and puts it in the hidden iframe, in the "access_token" div. This file looks like this:
<!DOCTYPE html>
<html>
<body>
<div id="access_token"></div>
<script language="javascript">
_getHash = function (hash) {
if (hash.indexOf('#/') > -1) {
hash = hash.substring(hash.indexOf('#/') + 2);
} else if (hash.indexOf('#') > -1) {
hash = hash.substring(1);
}
return hash;
};
_deserialize = function (query) {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) {
return decodeURIComponent(s.replace(pl, ' '));
},
obj = {};
match = search.exec(query);
while (match) {
obj[decode(match[1])] = decode(match[2]);
match = search.exec(query);
}
return obj;
};
var hash = _getHash(window.location.hash);
var params = _deserialize(hash);
document.getElementById("access_token").innerHTML = params["access_token"];
</script>
</body>
</html>
But, this process won't work when we need to renew the token.
Has anyone made any progress on this?
Is this the correct usage of this function? I seem to be getting an error " Build: Property 'subscribe' does not exist on type '() => Observable<{}>'"
this.adalService.acquireToken("http://whatever") .subscribe( data => { alert(data); }, error => { alert('error!'); } );