How to use the @foal/core.Config.get function in @foal/core

To help you get started, we’ve selected a few @foal/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FoalTS / foal / packages / csrf / src / set-csrf-cookie.ts View on Github external
export function setCsrfCookie(response: HttpResponse, csrfToken: string): void {
  const cookieName = Config.get('settings.csrf.cookie.name', CSRF_DEFAULT_COOKIE_NAME);
  const options: CookieOptions = {
    domain: Config.get('settings.csrf.cookie.domain'),
    httpOnly: false,
    path: Config.get('settings.csrf.cookie.path', CSRF_DEFAULT_COOKIE_PATH),
    sameSite: Config.get('settings.csrf.cookie.sameSite'),
    secure: Config.get('settings.csrf.cookie.secure')
  };
  // Express does not support options.maxAge === undefined.
  const maxAge = Config.get('settings.csrf.cookie.maxAge');
  if (maxAge) {
    options.maxAge = maxAge;
  }
  response.setCookie(cookieName, csrfToken, options);
}
github FoalTS / foal / packages / csrf / src / set-csrf-cookie.ts View on Github external
export function setCsrfCookie(response: HttpResponse, csrfToken: string): void {
  const cookieName = Config.get('settings.csrf.cookie.name', CSRF_DEFAULT_COOKIE_NAME);
  const options: CookieOptions = {
    domain: Config.get('settings.csrf.cookie.domain'),
    httpOnly: false,
    path: Config.get('settings.csrf.cookie.path', CSRF_DEFAULT_COOKIE_PATH),
    sameSite: Config.get('settings.csrf.cookie.sameSite'),
    secure: Config.get('settings.csrf.cookie.secure')
  };
  // Express does not support options.maxAge === undefined.
  const maxAge = Config.get('settings.csrf.cookie.maxAge');
  if (maxAge) {
    options.maxAge = maxAge;
  }
  response.setCookie(cookieName, csrfToken, options);
}
github FoalTS / foal / packages / acceptance-tests / src / authentication / jwt.jwks.spec.ts View on Github external
it('from AWS Cognito.', async () => {
    const clientId = Config.get('cognito.clientId');
    const domain = Config.get('cognito.domain');
    const refreshToken = Config.get('cognito.refreshToken');
    let token: string;
    const region = Config.get('cognito.region');
    const userPoolId = Config.get('cognito.userPoolId');

    if (refreshToken === undefined) {
      console.log('COGNITO_REFRESH_TOKEN not defined. Skipping this test...');
      return;
    }

    try {
      const { body } = await superagent
        .post(`https://${domain}.auth.${region}.amazoncognito.com/oauth2/token`)
        .send('grant_type=refresh_token')
        .send(`client_id=${clientId}`)
        .send(`refresh_token=${refreshToken}`);
github FoalTS / foal / packages / acceptance-tests / src / authentication / jwt.jwks.spec.ts View on Github external
it('from Auth0.', () => {
    const domain = Config.get('auth0.domain');
    const audience = Config.get('auth0.audience');
    const token = Config.get('auth0.token');

    if (token === undefined) {
      console.log('AUTH0_TOKEN not defined. Skipping this test...');
      return;
    }

    class AppController {

      @Get('/api/users/me')
      @JWTRequired({
        secretOrPublicKey: getRSAPublicKeyFromJWKS({
          cache: true,
          jwksRequestsPerMinute: 5,
          jwksUri: `https://${domain}/.well-known/jwks.json`,
github FoalTS / foal / packages / acceptance-tests / src / authentication / jwt.jwks.spec.ts View on Github external
it('from AWS Cognito.', async () => {
    const clientId = Config.get('cognito.clientId');
    const domain = Config.get('cognito.domain');
    const refreshToken = Config.get('cognito.refreshToken');
    let token: string;
    const region = Config.get('cognito.region');
    const userPoolId = Config.get('cognito.userPoolId');

    if (refreshToken === undefined) {
      console.log('COGNITO_REFRESH_TOKEN not defined. Skipping this test...');
      return;
    }

    try {
      const { body } = await superagent
        .post(`https://${domain}.auth.${region}.amazoncognito.com/oauth2/token`)
        .send('grant_type=refresh_token')
        .send(`client_id=${clientId}`)
        .send(`refresh_token=${refreshToken}`);
      token = body.id_token;
github FoalTS / foal / packages / acceptance-tests / src / authentication / jwt.token.spec.ts View on Github external
private async generateLoginResponse(user: User): Promise {
      const payload = {
        email: user.email,
        id: user.id,
      };
      const secret = Config.get('settings.jwt.secretOrPublicKey');

      const token = await new Promise((resolve, reject) => {
        sign(payload, secret, { subject: user.id.toString() }, (err, value: string) => {
          if (err) {
            return reject(err);
          }
          resolve(value);
        });
      });

      return new HttpResponseOK({
        token
      });
    }
  }
github FoalTS / foal / samples / tutorials / nuxt.js / backend / src / index.ts View on Github external
const builder = new Builder(nuxt);
    await builder.build();
  } else {
    await nuxt.ready();
  }

  await createConnection();

  const app = createApp(AppController, {
    postMiddlewares: [
      nuxt.render
    ]
  });

  const httpServer = http.createServer(app);
  const port = Config.get('port', 3001);
  httpServer.listen(port, () => {
    console.log(`Listening on port ${port}...`);
  });
}
github FoalTS / foal / packages / cli / src / generate / specs / app / src / index.ts View on Github external
async function main() {
  await createConnection();

  const app = createApp(AppController);

  const httpServer = http.createServer(app);
  const port = Config.get('port', 3001);
  httpServer.listen(port, () => {
    console.log(`Listening on port ${port}...`);
  });
}
github FoalTS / foal / packages / cli / src / generate / specs / app / src / index.mongodb.ts View on Github external
async function main() {
  const uri = Config.get('mongodb.uri');
  connect(uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true });

  const app = createApp(AppController);

  const httpServer = http.createServer(app);
  const port = Config.get('port', 3001);
  httpServer.listen(port, () => {
    console.log(`Listening on port ${port}...`);
  });
}
github FoalTS / foal / packages / csrf / src / get-csrf-token.util.ts View on Github external
export async function getCsrfToken(session?: Session): Promise {
  if (!Config.get('settings.csrf.enabled', true)) {
    return 'CSRF protection disabled';
  }

  if (session) {
    const csrfToken = session.get('csrfToken');
    if (!csrfToken) {
      throw new Error('CSRF token is missing in the session.');
    }
    return csrfToken;
  }

  const secret = Config.get('settings.csrf.secret');
  if (!secret) {
    throw new Error(
      '[CONFIG] You must provide a secret with the configuration key settings.csrf.secret.'
    );