// Copyright © 2022-2026 Partium, Inc. DBA Partium import { Observable } from 'rxjs'; import { OauthAuthenticationConfig } from '../../models/auth-config'; import { BACKEND_SERVICE, BaseUrls, HttpsService } from './https.service.interface'; import { ServiceProvider } from '../service-provider'; /** * Implementation of https service that provides authorization with oauth. */ export declare class OauthHttpsService extends HttpsService { protected authToken: string; protected authTokenExpiresAt: Date; private oauthSessionService; constructor(serviceProvider: ServiceProvider); onCreate(): void; /** * Initialize the https-service for OAuth authentication. * If the configuration contains an API-Key, directly create a * user-session, by calling login. * * @param baseUrls: the base-urls for the different backends * @param config the oauth auth-configuration */ init(baseUrls: BaseUrls, config: OauthAuthenticationConfig): Observable; /** * It is not sufficient that the token is set on init, because it can change when for example * a refresh is required. * * @param authToken the auth token * @param tokenExpiresAt token expiration timestamp */ setToken(authToken: string, authTokenExpiresAt: Date): void; /** * * Send GET request to the server with the given url and content. * * Wrap the parent-get into an observable that refreshes the oauth-session if it * would expire within the next few seconds otherwise. * We do this in order to avoid that requests fail and have to be retried after * refresh (which would/does happen automatically) * * @param url the relative server url * @param urlParams array of url parameters (as objects) which will be appended to the url ?p1=x&p2=y * @param beService to which backend-service should the request be sent (default PARTIUM) * @returns Observable that resolves with the request result */ get(url: string, urlParams?: Array, beService?: BACKEND_SERVICE): Observable; /** * * Send POST request to the server with the given url and content. * * Wrap the parent-post into an observable that refreshes the oauth-session if it * would expire within the next few seconds otherwise. * We do this in order to avoid that requests fail and have to be retried after * refresh (which would/does happen automatically) * * @param url the relative server url * @param data the data to be sent with the post request * @param urlParams array of url parameters (as objects) which will be appended to the url ?p1=x&p2=y * @param beService to which backend-service should the request be sent (default PARTIUM) * @param headers object with custom headers to send with the request * @returns Observable that resolves with the request result */ post(url: string, data: Object, urlParams?: Array, beService?: BACKEND_SERVICE, headers?: Object): Observable; /** * * Send PATCH request to the server with the given url and content. * * Wrap the parent-patch into an observable that refreshes the oauth-session if it * would expire within the next few seconds otherwise. * We do this in order to avoid that requests fail and have to be retried after * refresh (which would/does happen automatically) * * @param url the relative server url * @param data the data to be sent with the patch request * @param urlParams array of url parameters (as objects) which will be appended to the url ?p1=x&p2=y * @param beService to which backend-service should the request be sent (default PARTIUM) * @param headers object with custom headers to send with the request * @returns Observable that resolves with the request result */ patch(url: string, data: Object, urlParams?: Array, beService?: BACKEND_SERVICE, headers?: Object): Observable; /** * Called whenever a request fails to decide whether it should be * repeated or not. * If the request failed because the access-token expired, the session * is refreshed and the request retried afterwards. * * @param errors the errors Observable given by rxjs-retryWhen */ protected retryWhen(errors: Observable): Observable; /** * Overwrite the parent-class createHeaders to add the authentication-token * to the request. * * @param options object with given header-parameters that will be extended with more parameters * @returns the created headers object */ protected createHeaders(options?: Object): Object; private callOauthLogin; /** * Check whether the session will expire within the next few seconds. * If so, refresh the access-token, before continuing * * @returns true if the session will only be valid for a few more seconds, false otherwise */ private refreshSessionIfNeeded; /** * Try to refresh the current session. * If the refresh fails, because the refresh-token is expired, try to login again. * * @returns Observable of the refresh/login request */ private refreshOrLogin; }