public accessTokenData()

in desktop/src/app/services/aad/auth.service.ts [207:250]


    public accessTokenData(
        tenantId: string, resource: AADResourceName = null, forceRefresh = false
    ): Observable<AccessToken> {
        const key = [tenantId, resource].join("|");
        if (key in this.tokenObservableCache) {
            if (forceRefresh) {
                delete this.tokenObservableCache[key];
            } else {
                return this.tokenObservableCache[key];
            }
        }
        if (this.tokenCache.hasToken(tenantId, resource)) {
            const token = this.tokenCache.getToken(tenantId, resource);

            if (!token.expireInLess(Constants.AAD.refreshMargin)) {
                return of(token);
            }
        }

        const promise: Promise<AccessToken | AuthEvent> = this.remote.send(
            Constants.IpcEvent.AAD.accessTokenData,
            { tenantId, resource, forceRefresh }
        );
        promise.then((_) => this.authEvents["AuthComplete"].emit());
        const tokenObservable = from(promise).pipe(
            map((tokenData: AccessToken | AuthEvent) => {
                if (isAuthEvent(tokenData)) {
                    throw new AuthFlowException(tokenData);
                }
                const token = new AccessToken({ ...tokenData });
                this.tokenCache.storeToken(tenantId, resource, token);
                delete this.tokenObservableCache[key];
                return token;
            }),
            catchError(error => {
                delete this.tokenObservableCache[key];
                if (!(error instanceof AuthFlowException)) {
                    return throwError(error);
                }
            })
        );
        this.tokenObservableCache[key] = tokenObservable;
        return tokenObservable;
    }