<commit_before>/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file
 * This implements a CredentialsProvider based on Keycloak.
 */

import * as Keycloak from 'keycloak-js';
import {CredentialsProvider, makeCredentialsGetter} from 'neuroglancer/credentials_provider';
import {StatusMessage} from 'neuroglancer/status';
import {CANCELED, CancellationTokenSource} from 'neuroglancer/util/cancellation';

export type BossToken = string;

export class KeycloakService {
  static auth: any = {};

  static initialized: boolean = false;

  static init(authServer: string): Promise<any> {
    const keycloakAuth = Keycloak({url: authServer, realm: 'BOSS', clientId: 'endpoint'});

    KeycloakService.auth.loggedIn = false;

    return new Promise((resolve, reject) => {
      keycloakAuth.init({onLoad: 'login-required', responseMode: 'query'})
          .success(() => {
            KeycloakService.auth.loggedIn = true;
            KeycloakService.auth.authz = keycloakAuth;
            resolve();
          })
          .error(() => {
            reject();
          });
    });
  }
}

export class BossCredentialsProvider extends CredentialsProvider<BossToken> {
  constructor(public authServer: string) {
    super();
  }

  get = makeCredentialsGetter(cancellationToken => {
    const status = new StatusMessage(/*delay=*/true);
    let cancellationSource: CancellationTokenSource|undefined;
    return new Promise<BossToken>((resolve, reject) => {
      const dispose = () => {
        cancellationSource = undefined;<commit_msg>fix(datasource/boss): disable iframe to work with old keycloak server.<commit_after>/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file
 * This implements a CredentialsProvider based on Keycloak.
 */

import * as Keycloak from 'keycloak-js';
import {CredentialsProvider, makeCredentialsGetter} from 'neuroglancer/credentials_provider';
import {StatusMessage} from 'neuroglancer/status';
import {CANCELED, CancellationTokenSource} from 'neuroglancer/util/cancellation';

export type BossToken = string;

export class KeycloakService {
  static auth: any = {};

  static initialized: boolean = false;

  static init(authServer: string): Promise<any> {
    const keycloakAuth = Keycloak({url: authServer, realm: 'BOSS', clientId: 'endpoint'});

    KeycloakService.auth.loggedIn = false;

    return new Promise((resolve, reject) => {
      keycloakAuth.init({onLoad: 'login-required', responseMode: 'query', 'checkLoginIframe': false})
          .success(() => {
            KeycloakService.auth.loggedIn = true;
            KeycloakService.auth.authz = keycloakAuth;
            resolve();
          })
          .error(() => {
            reject();
          });
    });
  }
}

export class BossCredentialsProvider extends CredentialsProvider<BossToken> {
  constructor(public authServer: string) {
    super();
  }

  get = makeCredentialsGetter(cancellationToken => {
    const status = new StatusMessage(/*delay=*/true);
    let cancellationSource: CancellationTokenSource|undefined;
    return new Promise<BossToken>((resolve, reject) => {
      const dispose = () => {
        cancellationSource = undefined;
{'fraction_non_alphanumeric': 0.105890603085554, 'fraction_numerical': 0.0037400654511453952, 'mean_word_length': 3.635969664138678, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5392764', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1166, 'n_words': 371}