Skip to content

Latest commit

 

History

History
53 lines (42 loc) · 1.24 KB

readme.md

File metadata and controls

53 lines (42 loc) · 1.24 KB

Home server authenticator

A injectable (InversifyJS) class which implements Authenticator interface.
When creating inversify bindings:

Important

Include these environment variables (In your .env file) for home authenticator configuration:

## Authentication ##
HOME_GRAPHQL_AUTHENTICATION_URL = 'http://localhost:27230/graphql'
import {
  Authenticator,
  HomeServerAuthenticator,
  MockKeycloakAuthenticator
} from 'aos-server-utils';
...

container
    .bind<Authenticator>(TYPES.Authenticator)
    // Bind with MockKeycloakAuthenticator to mock Keycloak during development
    .to(HomeServerAuthenticator)
    .inSingletonScope();

When initializing express:

import { Authenticator} from 'aos-server-utils';
...

const auth: Authenticator = container.get(TYPES.Authenticator);
server.use(auth.getAuthenticator().middleware());
server.createRouter('/v1/', auth);

To get user in your controller, make sure your last parameter is 'context'.
Example:

@post('/update')
  public async updateSettings(req: Request, res: Response, context: any) {
    const response = await this.settingService.modifySettings(
      context.user,
      req.body
    );
    res.status(200).json(response);
  }