Skip to content

Instantly share code, notes, and snippets.

@camilogiraldo
Created August 15, 2019 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camilogiraldo/d29f66f4509eb3fcdaad7f543a94ca46 to your computer and use it in GitHub Desktop.
Save camilogiraldo/d29f66f4509eb3fcdaad7f543a94ca46 to your computer and use it in GitHub Desktop.
Angular 2 solution

For those wondering on how to tackle this issue in angular 2, using the solution purposed here: https://gist.github.com/tushargupta51/5fa6d000357120adbc8fd1d5c68853c4#gistcomment-2596636 It's as simple as this

After creating the redirect.html

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Frame Redirect</title>
    <script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.17/js/adal.min.js"></script>
</head>
<body>
<script>
  var adalConfig = {
    clientId: "guid-goes-here"
  };
  var authContext = new AuthenticationContext(adalConfig);
  authContext.handleWindowCallback();

  if (window === window.parent) { window.location.replace(location.origin + location.hash); }
</script>
</body>
</html>

In your angular.json add the following line

...
build: {
  ...
  "assets": [
    ...
    "src/redirect.html",
    ],
  ...
}
...

Don't forget to point the returnURI configuration over azure active directory to the new created /redirect.html

@nn-afly
Copy link

nn-afly commented Aug 17, 2019

Thank you for this.

I notice that the iframe is lost when the user refreshes the page, do you know if it will be regenerated? It is a PITA to test!

@camilogiraldo
Copy link
Author

@nn-afly Yes, I've noticed that, but I don't have details over how/why adal does this. A good question is "is it worth to test that?" as basically you're relying on a external library for that, so you'd assume that's already been tested. I would purpose just to test scenarios like logged in or not. Or what kind of scenarios would you like to cover ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment