1.0.188-dev • Published 4 months ago

@stegoconnect/ngx-connect-api v1.0.188-dev

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

STEGO CONNECT API Angular Module

This package contains the msal authentication required for getting an access token for the STEGO CONNECT. Is also contains services for all STEGO CONNECT APIs and the respective model classes. This package is intended to be used in Angular projects.

Peer dependencies

The package requires Angular 12 and the Angular MSAL packages @azure/msal-angular and @azure/msal-browser in at least version 2.0.2.

Usage

import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MsalGuard, MsalInterceptor, MsalModule, MsalRedirectComponent } from '@azure/msal-angular';
import { ApiModule, ConnectApiModule, getApiConfiguration, getMsalConfiguration } from '@stegoconnect/ngx-connect-api';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

const msalConfiguration = getMsalConfiguration('<clientId of the third party app>', '<redirectUrl of the third party app>', '<dev or prod, depending what environment to authenticate against>');
const apiConfiguration = getApiConfiguration('<dev or prod, depending which api should be called>');

@NgModule({
    declarations: [AppComponent],
    imports: [BrowserModule, HttpClientModule, AppRoutingModule, ConnectApiModule, ApiModule.forRoot(() => apiConfiguration), MsalModule.forRoot(...msalConfiguration)],
    providers: [
        MsalGuard,
        {
            provide: HTTP_INTERCEPTORS,
            useClass: MsalInterceptor,
            multi: true,
        },
    ],
    bootstrap: [AppComponent, MsalRedirectComponent],
})
export class AppModule {}

Calling the API

The API can be called by using the existing API services. The tenant id is received based on the application url (e.g. https://thirdpartyapp.de/tenantId). It can be injected with the TENANT_ID token.

@Component({
    selector: 'app-home',
    templateUrl: './home.component.html',
    styleUrls: ['./home.component.scss'],
})
export class HomeComponent implements OnInit {
    public edgeDevices$: Observable<EdgeDeviceItemsResult> = of();

    constructor(@Inject(TENANT_ID) private readonly tenantId: string, private readonly edgeDeviceService: EdgeDevicesService) {}

    public ngOnInit(): void {
        this.edgeDevices$ = this.edgeDeviceService.getEdgeDevices(this.tenantId);
    }
}

Redirect to tenant with permission

The current tenant is ready from the url of the application. The SDK comes with an Angular startup service that can be used to redirect the current user to either the first tenant they have permission if the user has no permissions to the specified tenant or to redirect them to a not found page if they have no permissions to any tenant. You can add this behavior by specificing the following in the app.component:

providers: [
        ...
        TenantStartupService,
        {
            provide: APP_INITIALIZER,
            useFactory: tenantStartupServiceFactory,
            deps: [TenantStartupService],
            multi: true,
        },
    ],
1.0.188-dev

4 months ago

1.0.166-dev

6 months ago

1.0.153-dev

8 months ago

1.0.171-dev

6 months ago

1.0.153-prev

8 months ago

1.0.150-prev

9 months ago

1.0.150-dev

9 months ago

1.0.153

8 months ago

1.0.172-dev

6 months ago

1.0.150

9 months ago

1.0.171

6 months ago

1.0.171-prev

6 months ago

1.0.120

1 year ago

1.0.120-prev

1 year ago

1.0.116-dev

1 year ago

1.0.120-dev

1 year ago

1.0.114-prev

1 year ago

1.0.119

1 year ago

1.0.114

1 year ago

1.0.119-dev

1 year ago

1.0.119-prev

1 year ago

1.0.114-dev

1 year ago

1.0.105-dev

1 year ago

1.0.105-prev

1 year ago

1.0.87-dev

2 years ago

1.0.83-prev

2 years ago

1.0.88-prev

2 years ago

1.0.83-dev

2 years ago

1.0.85-prev

2 years ago

1.0.86-prev

2 years ago

1.0.88-dev

2 years ago

1.0.87-prev

2 years ago

1.0.86-dev

2 years ago

1.0.84-dev

2 years ago

1.0.82-dev

2 years ago

1.0.88

2 years ago

1.0.87

2 years ago

1.0.86

2 years ago

1.0.85

2 years ago

1.0.84-prev

2 years ago

1.0.85-dev

2 years ago

1.0.6-dev

3 years ago

1.0.5-dev

3 years ago