4

I'm trying to use Azure Access Control Service in HTML/JavaScript application. The following code sample is going to display token after authentication against selected identity provider:

<!DOCTYPE html>
<html>
<head>
</head>

<body>
<script type="text/javascript">
    function handleData (data){
    
        document.getElementById('tokenDiv').innerHTML = "Token = " + data;
    }
    function chooseIdentityProvider ( url ){
    
        document.getElementById('loginFrame').src = url;            
    }
    // HOW TO register notify event handler?    
    window.external.notify = handleData;        
</script>
<select name="AvailableProviders" onchange="if (this.selectedIndex) chooseIdentityProvider (this.value)">
    <option value="-1">Select Identity Provider</option>
    <option value="https://login.live.com/login.srf?wa=wsignin1.0&wtrealm=https%3a%2f%2faccesscontrol.windows.net%2f&wreply=https%3a%2f%2fnamespace.accesscontrol.windows.net%3a443%2fv2%2fwsfederation&wp=MBI_FED_SSL&wctx=pr%3djavascriptnotify%26rm%3duri%253awk%253atest">Windows Live ID</option>  
    <option value="https://www.google.com/accounts/o8/ud?openid.ns=http%3a%2f%2fspecs.openid.net%2fauth%2f2.0&openid.mode=checkid_setup&openid.claimed_id=http%3a%2f%2fspecs.openid.net%2fauth%2f2.0%2fidentifier_select&openid.identity=http%3a%2f%2fspecs.openid.net%2fauth%2f2.0%2fidentifier_select&openid.realm=https%3a%2f%2fnamespace.accesscontrol.windows.net%3a443%2fv2%2fopenid&openid.return_to=https%3a%2f%2fnamespace.accesscontrol.windows.net%3a443%2fv2%2fopenid%3fcontext%3dpr%253djavascriptnotify%2526rm%253duri%25253awk%25253atest%26provider%3dGoogle&openid.ns.ax=http%3a%2f%2fopenid.net%2fsrv%2fax%2f1.0&openid.ax.mode=fetch_request&openid.ax.required=email%2cfullname%2cfirstname%2clastname&openid.ax.type.email=http%3a%2f%2faxschema.org%2fcontact%2femail&openid.ax.type.fullname=http%3a%2f%2faxschema.org%2fnamePerson&openid.ax.type.firstname=http%3a%2f%2faxschema.org%2fnamePerson%2ffirst&openid.ax.type.lastname=http%3a%2f%2faxschema.org%2fnamePerson%2flast">Google</option>
    <option value="https://open.login.yahooapis.com/openid/op/auth?openid.ns=http%3a%2f%2fspecs.openid.net%2fauth%2f2.0&openid.mode=checkid_setup&openid.claimed_id=http%3a%2f%2fspecs.openid.net%2fauth%2f2.0%2fidentifier_select&openid.identity=http%3a%2f%2fspecs.openid.net%2fauth%2f2.0%2fidentifier_select&openid.realm=https%3a%2f%2fnamespace.accesscontrol.windows.net%3a443%2fv2%2fopenid&openid.return_to=https%3a%2f%2fnamespace.accesscontrol.windows.net%3a443%2fv2%2fopenid%3fcontext%3dpr%253djavascriptnotify%2526rm%253duri%25253awk%25253atest%26provider%3dYahoo!&openid.ns.ax=http%3a%2f%2fopenid.net%2fsrv%2fax%2f1.0&openid.ax.mode=fetch_request&openid.ax.required=email%2cfullname%2cfirstname%2clastname&openid.ax.type.email=http%3a%2f%2faxschema.org%2fcontact%2femail&openid.ax.type.fullname=http%3a%2f%2faxschema.org%2fnamePerson&openid.ax.type.firstname=http%3a%2f%2faxschema.org%2fnamePerson%2ffirst&openid.ax.type.lastname=http%3a%2f%2faxschema.org%2fnamePerson%2flast">Yahoo!</option>"
</select> 
<br />
<iframe id="loginFrame" height="200" width="60%" src="" />
<br />
<div id="tokenDiv"></div>
</body>
</html>

The content of the iFrame is like:

<script type="text/javascript">
try{
    window.external.notify(...token...);
}
catch(err){
    alert("Error ACS50021: windows.external.Notify is not registered.");
}
</script>

I'm getting error:

"Error ACS50021: windows.external.Notify is not registered."

How can I register the notify event handler in the JavaScript?

3
  • Is this is in a browser or a "browser control"? Commented Feb 14, 2012 at 20:57
  • This is browser, and could be used in browser control on mobile devices wrapped by phonegap Commented Feb 14, 2012 at 22:35
  • 2
    I don't think browsers support this. I think it's just the browser control in .NET that does. Commented Feb 15, 2012 at 14:18

2 Answers 2

2

Have you enable the allowed url to receive the message, something like this:

            // code needed -> allowed parameter to check all URL
        var unloadFunc = "(function(){ function navigating(){ window.external.notify('%%' + location.href);} window.onbeforeunload=navigating;return location.href;})();";
        var host = wv.InvokeScript("eval", new string[] { unloadFunc });
        wv.AllowedScriptNotifyUris = new[] { new Uri(host) };

wv is the webview element in xaml

Sign up to request clarification or add additional context in comments.

Comments

0

If you are using an iFrame you will need to use the postMessage API. http://msdn.microsoft.com/en-us/library/ie/cc197015(v=vs.85).aspx

window.external.notify is an API that only works in the XAML WebView control, or the HTML x-ms-webview control.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.