<commit_before>import { Injectable, NgZone, Optional, OnDestroy, Inject } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import {
  Observable,
  Subject,
  Subscription,
  of,
  race,
  from,
  combineLatest
} from 'rxjs';
import {
  filter,
  delay,
  first,
  tap,
  map,
  switchMap,
  debounceTime
} from 'rxjs/operators';
import { DOCUMENT } from '@angular/common';

import {
  ValidationHandler,
  ValidationParams
} from './token-validation/validation-handler';
import { UrlHelperService } from './url-helper.service';
import {
  OAuthEvent,
  OAuthInfoEvent,
  OAuthErrorEvent,
  OAuthSuccessEvent
} from './events';
import {
  OAuthLogger,
  OAuthStorage,
  LoginOptions,
  ParsedIdToken,
  OidcDiscoveryDoc,
  TokenResponse,
  UserInfo
} from './types';
import { b64DecodeUnicode, base64UrlEncode } from './base64-helper';
import { AuthConfig } from './auth.config';
import { WebHttpUrlEncodingCodec } from './encoder';
import { HashHandler } from './token-validation/hash-handler';

/**
 * Service for logging in and logging out with
 * OIDC and OAuth2. Supports implicit flow and
 * password flow.
 */
@Injectable()
export class OAuthService extends AuthConfig implements OnDestroy {
  // Extending AuthConfig ist just for LEGACY reasons
  // to not break existing code.

  /**
   * The ValidationHandler used to validate received
   * id_tokens.
   */
  public tokenValidationHandler: ValidationHandler;

  /**
   * @internal
   * Deprecated:  use property events instead
   */
  public discoveryDocumentLoaded = false;

  /**
   * @internal
   * Deprecated:  use property events instead
   */
  public discoveryDocumentLoaded$: Observable<OidcDiscoveryDoc>;

  /**
   * Informs about events, like token_received or token_expires.
   * See the string enum EventType for a full list of event types.
   */
  public events: Observable<OAuthEvent>;

  /**
   * The received (passed around) state, when logging
   * in with implicit flow.
   */
  public state? = '';

  protected eventsSubject: Subject<OAuthEvent> = new Subject<OAuthEvent>();
  protected discoveryDocumentLoadedSubject: Subject<
    OidcDiscoveryDoc
  > = new Subject<OidcDiscoveryDoc>();
  protected silentRefreshPostMessageEventListener: EventListener;
  protected grantTypesSupported: Array<string> = [];
  protected _storage: OAuthStorage;
  protected accessTokenTimeoutSubscription: Subscription;
  protected idTokenTimeoutSubscription: Subscription;
  protected tokenReceivedSubscription: Subscription;
  protected sessionCheckEventListener: EventListener;
  protected jwksUri: string;
  protected sessionCheckTimer: any;
  protected silentRefreshSubject: string;
  protected inImplicitFlow = false;

  protected saveNoncesInLocalStorage = false;

  constructor(
    protected ngZone: NgZone,
    protected http: HttpClient,
    @Optional() storage: OAuthStorage,
    @Optional() tokenValidationHandler: ValidationHandler,
    @Optional() protected config: AuthConfig,
    protected urlHelper: UrlHelperService,
    protected logger: OAuthLogger,
    @Optional() protected crypto: HashHandler,
    @Inject(DOCUMENT) private document: Document
  ) {
    super();

    this.debug('angular-oauth2-oidc v8-beta');<commit_msg>Fix issue with ambient type in constructor when running Universal with Ivy<commit_after>import { Injectable, NgZone, Optional, OnDestroy, Inject } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import {
  Observable,
  Subject,
  Subscription,
  of,
  race,
  from,
  combineLatest
} from 'rxjs';
import {
  filter,
  delay,
  first,
  tap,
  map,
  switchMap,
  debounceTime
} from 'rxjs/operators';
import { DOCUMENT } from '@angular/common';

import {
  ValidationHandler,
  ValidationParams
} from './token-validation/validation-handler';
import { UrlHelperService } from './url-helper.service';
import {
  OAuthEvent,
  OAuthInfoEvent,
  OAuthErrorEvent,
  OAuthSuccessEvent
} from './events';
import {
  OAuthLogger,
  OAuthStorage,
  LoginOptions,
  ParsedIdToken,
  OidcDiscoveryDoc,
  TokenResponse,
  UserInfo
} from './types';
import { b64DecodeUnicode, base64UrlEncode } from './base64-helper';
import { AuthConfig } from './auth.config';
import { WebHttpUrlEncodingCodec } from './encoder';
import { HashHandler } from './token-validation/hash-handler';

/**
 * Service for logging in and logging out with
 * OIDC and OAuth2. Supports implicit flow and
 * password flow.
 */
@Injectable()
export class OAuthService extends AuthConfig implements OnDestroy {
  // Extending AuthConfig ist just for LEGACY reasons
  // to not break existing code.

  /**
   * The ValidationHandler used to validate received
   * id_tokens.
   */
  public tokenValidationHandler: ValidationHandler;

  /**
   * @internal
   * Deprecated:  use property events instead
   */
  public discoveryDocumentLoaded = false;

  /**
   * @internal
   * Deprecated:  use property events instead
   */
  public discoveryDocumentLoaded$: Observable<OidcDiscoveryDoc>;

  /**
   * Informs about events, like token_received or token_expires.
   * See the string enum EventType for a full list of event types.
   */
  public events: Observable<OAuthEvent>;

  /**
   * The received (passed around) state, when logging
   * in with implicit flow.
   */
  public state? = '';

  protected eventsSubject: Subject<OAuthEvent> = new Subject<OAuthEvent>();
  protected discoveryDocumentLoadedSubject: Subject<
    OidcDiscoveryDoc
  > = new Subject<OidcDiscoveryDoc>();
  protected silentRefreshPostMessageEventListener: EventListener;
  protected grantTypesSupported: Array<string> = [];
  protected _storage: OAuthStorage;
  protected accessTokenTimeoutSubscription: Subscription;
  protected idTokenTimeoutSubscription: Subscription;
  protected tokenReceivedSubscription: Subscription;
  protected sessionCheckEventListener: EventListener;
  protected jwksUri: string;
  protected sessionCheckTimer: any;
  protected silentRefreshSubject: string;
  protected inImplicitFlow = false;

  protected saveNoncesInLocalStorage = false;
  private document: Document;

  constructor(
    protected ngZone: NgZone,
    protected http: HttpClient,
    @Optional() storage: OAuthStorage,
    @Optional() tokenValidationHandler: ValidationHandler,
    @Optional() protected config: AuthConfig,
    protected urlHelper: UrlHelperService,
    protected logger: OAuthLogger,
    @Optional() protected crypto: HashHandler,
    @Inject(DOCUMENT) document: any
  ) {
    super();

    this.debug('angular-oauth2-oidc v8-beta');

    // See https://github.com/manfredsteyer/angular-oauth2-oidc/issues/773 for why this is needed
    this.document = document;
{'fraction_non_alphanumeric': 0.09453625130266488, 'fraction_numerical': 0.003275271698675004, 'mean_word_length': 4.323296354992076, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '799312', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1879, 'n_words': 545}