# bc-adal-angular

> Library wrapper for Angular 6+, development over Microsoft ADAL (Azure Active Directory Authentication Library) - [https://github.com/AzureAD/azure-activedirectory-library-for-js](https://github.com/AzureAD/azure-activedirectory-library-for-js) that helps

Latest version **0.0.6** (published 2019-01-20) · 0 weekly downloads

## Install

```sh
npm install bc-adal-angular
pnpm add bc-adal-angular
yarn add bc-adal-angular
bun add bc-adal-angular
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2019-01-20 |
| First published | 2018-11-26 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 176.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | dericop |

## Links

- npm: https://www.npmjs.com/package/bc-adal-angular
- Repository: https://github.com/dericop/ADALWrapper
- Homepage: https://github.com/dericop/ADALWrapper#readme
- Issues: https://github.com/dericop/ADALWrapper/issues
- npm.io page: https://npm.io/package/bc-adal-angular

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0
- [adal-angular](https://npm.io/package/adal-angular.md) ^1.0.17

## Recent versions

- 0.0.6 (latest) — 2019-01-20
- 0.0.5 — 2019-01-18
- 0.0.4 — 2019-01-18
- 0.0.3 — 2019-01-17
- 0.0.2 — 2018-11-26

## README

# BC Adal Angular Library

### Active Directory Authentication Library (ADAL) for Angular6

Library wrapper for Angular 6+, development over Microsoft ADAL (Azure Active Directory Authentication Library) - [https://github.com/AzureAD/azure-activedirectory-library-for-js](https://github.com/AzureAD/azure-activedirectory-library-for-js) that helps you integrate with Microsoft's AAD (Azure Active Directory).

<!-- Demo: [https://github.com/manishrasrani/ms-adal-angular6-example](https://github.com/manishrasrani/ms-adal-angular6-example) -->

---

For information on how to configure Azure Active Directory refer - [https://docs.microsoft.com/en-us/azure/app-service/app-service-mobile-how-to-configure-active-directory-authentication](https://docs.microsoft.com/en-us/azure/app-service/app-service-mobile-how-to-configure-active-directory-authentication)

<h2>How to use library</h2>

**Step 1: Install the package**

```bash
npm i --save bc-adal-angular
```

**Step 2: Import BcAdalAngularModule and configure Adal Options**

In the root module of your application, import the `BcAdalAngularModule` module.

```typescript
import { BcAdalAngularModule } from 'bc-adal-angular';
```

Configure Adal Options while importing the module.

```typescript
@NgModule({
  imports: [
    BcAdalAngularModule.forRoot({
      tenant: '[Enter your tenant]',
      clientId: '[Enter your client_id here, e.g. g075edef-0efa-453b-997b-de1337c29185]',
      redirectUri: window.location.origin,
      // ...
    }),
    // ...
  ],
  // ...
})
```

For a list of all available adal configuration options, refer:
[https://github.com/AzureAD/azure-activedirectory-library-for-js/wiki/Config-authentication-context#configurable-options](https://github.com/AzureAD/azure-activedirectory-library-for-js/wiki/Config-authentication-context#configurable-options)

**Step 3: Secure individual routes of Angular**

Use the AdalAccessGuard to secure indivuadual routes in your application.
Import AdalAccessGuard and add it as a provider in your root module.

> Note: This step it's optional, because the BcAdalAngularModule
> import the guard provider automatically

```typescript
import { AdalAccessGuard } from 'bc-adal-angular';
```

```typescript
@NgModule({
    providers: [
        // ...
        AdalAccessGuard,
        // ...
    ],
    // ...
})
```

In your routing module, add it to the routes you want to secure

```typescript
const routes: Routes = [
  {
    path: '',
    component: AppComponent,
    pathMatch: 'full',
    canActivate: [AdalAccessGuard]
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {
  /* ... */
}
```

**Step 4 (Optional): Generating resource tokens**

To generate resource level tokens for APIs your website may consume, specify the resources in your endpoints array while injecting AdalOptions into BcAdalAngularModule via root.
Then to generate token, use `getAccessToken()` of `BcAdalAngularService`:

```typescript
constructor(private adalService: BcAdalAngularService) {
  this.adalService
    .getAccessToken(
        endpoint: string,
        callbacks: (message: string, token: string) => any)
    .subscribe((resToken: string) => {
      console.log(resToken);
    });
}
```

**Step 5 (Optional): Getting logged-in user info**

At any point in you application, to get the logged-in user info, use:

```typescript
this.adalService.userInfo;
```

With these steps your application should be up and running with ADAL.

**Important links**

1. [Azure Active Directory Overview](https://docs.microsoft.com/en-us/azure/active-directory/active-directory-whatis)
2. [Configure Azure Active Directory](https://docs.microsoft.com/en-us/azure/app-service/app-service-mobile-how-to-configure-active-directory-authentication)
3. [Azure Active Directory Pricing](https://azure.microsoft.com/en-in/pricing/details/active-directory/)
4. [Active Directory Authentication Library (ADAL) for JavaScript](https://github.com/AzureAD/azure-activedirectory-library-for-js)

---
_Source: https://npm.io/package/bc-adal-angular · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
