@agilicus/angular

The published package is a library under projects/agilicus/angular. There is a sample application in the root directory for trying it.

Usage no npm install needed!

<script type="module">
  import agilicusAngular from 'https://cdn.skypack.dev/@agilicus/angular';
</script>

README

Agilicus Angular SDK

The published package is a library under projects/agilicus/angular. There is a sample application in the root directory for trying it.

The underlying API is available here.

Read the class-library documentation online

Dev

npm i
ng build agilicus-angular --watch
ng serve

Usage

Install peer dependencies

npm install --save node-fetch oidc-client short-uuid fast-json-patch

Code

In your app.module.ts:

import { ApiModule, apiConfigFactory } from '@agilicus/angular';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    HttpClientModule,
    ApiModule.forRoot(apiConfigFactory),
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

In your login flow (e.g. app.component.ts):

import { AgilicusAuth } from '@agilicus/angular';

export class AppComponent {
  title = 'angular';
  auth: AgilicusAuth;
  constructor() {
    this.auth = new AgilicusAuth('MY_CLIENT_ID', 'MY_AUTH_URI');
  }
}

You will have 2 items which can be configured or default:

To use a specific API, something like:

import { UsersService } from '@agilicus/angular';
...
   const id = this.auth.id();
   const org = this.auth.org();
   if (id && org) {
      const obs$ = this.usersService.getUser(id, org);
      obs$.subscribe( (user) => { console.log(user); });
   }

Running tests against the angular library

npm run test -- agilicus-angular

Scopes

Scopes may be provided when logging in to limit the set of permissions a user can access (for example specific APIs). Scopes are a space seperated string. Optional scopes are indicated by a ? at the end of the scope. Ex. "urn:agilicus:api:issuers:owner urn:agilicus:api:users:viewer? urn:agilicus:api:applications:owner"

Troubleshooting

Build

If you get errors like this, try running ng build in angular first. It's possible that the base dependencies haven't been built yet.

Compiling TypeScript sources through ngc
ERROR: node_modules/@angular/core/core.d.ts:256:18 - error TS2314: Generic type 'ɵɵFactoryDef' requires 1 type argument(s).

256     static ɵfac: ɵngcc0.ɵɵFactoryDef<ApplicationInitStatus, [{ optional: true; }]>;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/core/core.d.ts:439:18 - error TS2314: Generic type 'ɵɵFactoryDef' requires 1 type argument(s).

439     static ɵfac: ɵngcc0.ɵɵFactoryDef<ApplicationRef, never>;