當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Application.set方法代碼示例

本文整理匯總了TypeScript中@feathersjs/feathers.Application.set方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Application.set方法的具體用法?TypeScript Application.set怎麽用?TypeScript Application.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@feathersjs/feathers.Application的用法示例。


在下文中一共展示了Application.set方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

  /**
   * Create a new authentication service.
   * @param app The Feathers application instance
   * @param configKey The configuration key name in `app.get` (default: `authentication`)
   * @param options Optional initial options
   */
  constructor (app: Application, configKey: string = 'authentication', options = {}) {
    if (!app || typeof app.use !== 'function') {
      throw new Error('An application instance has to be passed to the authentication service');
    }

    this.app = app;
    this.strategies = {};
    this.configKey = configKey;

    app.set('defaultAuthentication', app.get('defaultAuthentication') || configKey);
    app.set(configKey, merge({}, app.get(configKey), options));
  }
開發者ID:feathersjs,項目名稱:feathers,代碼行數:18,代碼來源:core.ts

示例2: default

export default (app: Application) => {
  const authentication = new AuthenticationService(app);

  app.set('authentication', {
    entity: 'user',
    service: 'users',
    secret: 'supersecret',
    authStrategies: [ 'local', 'jwt' ],
    local: {
      usernameField: 'email',
      passwordField: 'password'
    }
  });

  authentication.register('jwt', new JWTStrategy());
  authentication.register('local', new LocalStrategy());

  app.use('/authentication', authentication);
  app.use('/users', memory({
    paginate: {
      default: 10,
      max: 20
    }
  }));

  app.service('users').hooks({
    before: {
      create: hashPassword('password')
    },
    after: protect('password')
  });

  app.use('/dummy', {
    find (params) {
      return Promise.resolve(params);
    }
  });

  app.service('dummy').hooks({
    before: authenticate('jwt')
  });

  app.service('users').hooks({
    before (context: HookContext) {
      if (context.id !== undefined && context.id !== null) {
        context.id = parseInt(context.id as string, 10);
      }

      return context;
    }
  });

  return app;
};
開發者ID:feathersjs,項目名稱:feathers,代碼行數:54,代碼來源:fixture.ts

示例3: constructor

  constructor (app: Application, options: AuthenticationClientOptions) {
    const socket = app.io || app.primus;
    const storage = new StorageWrapper(app.get('storage') || options.storage);

    this.app = app;
    this.options = options;
    this.authenticated = false;
    this.app.set('storage', storage);

    if (socket) {
      this.handleSocket(socket);
    }
  }
開發者ID:feathersjs,項目名稱:feathers,代碼行數:13,代碼來源:core.ts

示例4: it

    it('allows to override jwtOptions, does not merge', () => {
      const { jwtOptions } = auth.configuration;
      const auth2options = {
        jwtOptions: {
          expiresIn: '1w'
        }
      };

      app.set('auth2', auth2options);

      const auth2 = new AuthenticationBase(app, 'auth2');

      assert.ok(jwtOptions);
      assert.strictEqual(jwtOptions.expiresIn, '1d');
      assert.strictEqual(jwtOptions.issuer, 'feathers');

      assert.deepStrictEqual(auth2.configuration.jwtOptions, auth2options.jwtOptions);
    });
開發者ID:feathersjs,項目名稱:feathers,代碼行數:18,代碼來源:core.test.ts

示例5: it

    it('errors when no allowed strategies are set', async () => {
      const service = app.service('authentication');
      const configuration = service.configuration;

      delete configuration.authStrategies;

      app.set('authentication', configuration);

      try {
        await service.create({
          strategy: 'first',
          username: 'Dave'
        });
        assert.fail('Should never get here');
      } catch (error) {
        assert.strictEqual(error.name, 'NotAuthenticated');
        assert.strictEqual(error.message, 'No authentication strategies allowed for creating a JWT (`authStrategies`)');
      }
    });
開發者ID:feathersjs,項目名稱:feathers,代碼行數:19,代碼來源:service.test.ts

示例6: Error

export const setup = (options: OauthSetupSettings) => (app: Application) => {
  const authPath = options.authService;
  const service: AuthenticationService = app.service(authPath);

  if (!service) {
    throw new Error(`'${authPath}' authentication service must exist before registering @feathersjs/authentication-oauth`);
  }

  const { oauth } = service.configuration;

  if (!oauth) {
    debug(`No oauth configuration found at '${authPath}'. Skipping oAuth setup.`);
    return;
  }

  const { strategyNames } = service;
  const { path = '/auth' } = oauth.defaults;
  const grant = merge({
    defaults: {
      path,
      host: `${app.get('host')}:${app.get('port')}`,
      protocol: app.get('env') === 'production' ? 'https' : 'http',
      transport: 'session'
    }
  }, omit(oauth, 'redirect'));

  each(grant, (value, key) => {
    if (key !== 'defaults') {
      value.callback = value.callback || `${path}/${key}/authenticate`;

      if (!strategyNames.includes(key)) {
        debug(`Registering oAuth default strategy for '${key}'`);
        service.register(key, new OAuthStrategy());
      }
    }
  });

  app.set('grant', grant);
};
開發者ID:feathersjs,項目名稱:feathers,代碼行數:39,代碼來源:index.ts

示例7: authenticate

  authenticate (authentication: AuthenticationRequest): Promise<AuthenticationResult> {
    if (!authentication) {
      return this.reAuthenticate();
    }

    const promise = this.service.create(authentication)
      .then((authResult: AuthenticationResult) => {
        const { accessToken } = authResult;

        this.authenticated = true;
        this.app.emit('login', authResult);
        this.app.emit('authenticated', authResult);

        return this.setAccessToken(accessToken).then(() => authResult);
      }).catch((error: Error) =>
        this.reset().then(() => Promise.reject(error))
      );

    this.app.set('authentication', promise);

    return promise;
  }
開發者ID:feathersjs,項目名稱:feathers,代碼行數:22,代碼來源:core.ts

示例8: reset

  reset () {
    this.app.set('authentication', null);
    this.authenticated = false;

    return Promise.resolve(null);
  }
開發者ID:feathersjs,項目名稱:feathers,代碼行數:6,代碼來源:core.ts


注:本文中的@feathersjs/feathers.Application.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。