npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-adal-8

v0.0.5

Published

Angular 2+ ADAL Wrapper library

Downloads

26

Readme

NPM version License

Active Directory Authentication Library (ADAL) wrapper for (Angular X)

This library is a wrapper taking consideration different scenarios of how ADAL should be used with Angular 2+ without importing adal-angular in package.json

Reason:
You do not need to install "adal-angular": "^1.0.17" as that library is composed of adal.js and adal-angular.js.
adal-angular.js is the library for AngularJS meaning anything prior to Angular 2
adal.js is where the code we need is however since we need this file included in more than
one place installing this library is just plain redundant as we will still need to link
directly to adal.js and Microsoft serve it in their CDN for us or you could host it in your assets folder.

https://secure.aadcdn.microsoftonline-p.com/lib/1.0.17/js/adal.min.js

Also solutions revolving auth-callback.component.ts are wrong as ADAL will load the application a second time inside an iframe. So instead we load a frameRedirect.html inside the iframe just like we did in angularJS to avoid infinite loop.

Samples using this library at https://github.com/fairmutex/ngx-adal-8-samples these follow the the below instructions.

Registering Angular application with Azure can be found here
Take note of Application (client) ID (6) and Directory (tenant) Id (7)

In your angular.json under build section add "src/frameRedirect.html" as shown below to make it servable without triggering angular routing.

            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/frameRedirect.html"
            ],

Create frameRedirect.html under src folder and inside frameRedirect.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: 'YOUR_CLIENT_ID (6)'
      };
      var authContext = new AuthenticationContext(adalConfig);
      authContext.handleWindowCallback();

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

In index.html put

<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.17/js/adal.min.js"></script>

In app.module.ts

import { NgxAdalModule } from 'ngx-adal-8';

Imports section

NgxAdalModule.forRoot({
      tenant: `YOUR_TENANT_ID (7)`,
      clientId: `YOUR_CLIENT_ID (6)`,
      redirectUri: `frameRedirect.html`,
      postLogoutRedirectUri: `frameRedirect.html`,
      cacheLocation: 'localStorage',
    }),

3 App scenerios

App that either you are logged in or will send you to login upon visit

Without using guards

in your app.component.ts

import { NgxAdalService } from 'ngx-adal-8';
  constructor(private authService:NgxAdalService){
    if (!this.authService.isAuthenticated) {
      this.authService.login();
    }
  }

Using guards

In app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  {
    path: 'secured',
    component: SecuredComponent,
    pathMatch: 'full',
    canActivate: [NgxAdalGuard]
  },
  { path: 'unsecured', component: UnsecuredComponent, pathMatch: 'full' },
  { path: '**', redirectTo: 'unsecured' }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}

App that have public facing and some parts require login. In some component perhaps navbar.component.ts login/logout buttons

  constructor(private authService:NgxAdalService){

  }

  login(){
    this.authService.login();
  }

  logout(){
    this.authService.logout();
  }

Then use guards on the specific children routes.

Couldn't have done this without

  1. Help with ADAL back in 2016 Tushar Grupta
  2. ms-adal-angular6
  3. Several questions/answers on GitHub