Přeskočit na hlavní obsah

Impersonation

Introduction

Users can be members of more tenants/organizations. Therefore, he has to have access to it. There are two ways.

  • interactive - The user uses the tenant switch and switches the main token of the application
  • non-interactive - The user changes the scope of the request but does not know about it.

The first one is handled by the component TenancySwitchComponent and because it changes the main token of the application, there is nothing else to be handled by the developer.

Handling non-interactive changes in the scope will be described in this chapter.

AsolApiDataService

The first service that handles impersonation is AsolApiDataService. When it receives the last param in any of its methods, with tenantId and organization code of the new wanted scope, it adds Asol-Impersonation-Organization-Code and Asol-Impersonation-Tenant-Id with their value to the headers.

AsolAuthInterceptorService

When the interceptor finds those headers, it tries to get the impersonated token for it. It uses the AsolImpersonationService for it.

AsolImpersonationService

This service is responsible for getting and storing secondary tokens. Currently, it contains only one method

getToken(tenantId: string, organizationCode: string): Observable<string>

which accepts tenantId and organizationCode as its parameters. It returns observable with the found token. If the token is not stored yet or is expired, it requires a new one. Otherwise, it returns an already stored token.

The best way to use it is to use AsolApiDataService with every BE request, as those described services communicated, and provide everything necessary for the developer. For those, who found AsolApiDataService not suitable, you can try to use AsolImpersonationService directly, and use tokens from there.