Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.
This repository was archived by the owner on May 3, 2022. It is now read-only.

Authentication handlers should match Typescript interface #21

@singingwolfboy

Description

@singingwolfboy

The authentication handlers in auth.ts all define handleAuthentication methods that look like this:

handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs): Promise<ifm.IHttpClientResponse> {
    return null;
}

However, this is not strictly valid Typescript, since the actual return type does not match the declared return type. Notice that the actual return type is null, while the declared return type is Promise<ifm.IHttpClientResponse>.

Fixing this issue may require modifying the Typescript types to better describe intent. Here's one way we could do it:

export interface IRequestHandlerWithAuth {
  prepareRequest(options: http.RequestOptions): void;
  canHandleAuthentication(response: IHttpClientResponse): true;
  handleAuthentication(
    httpClient: IHttpClient,
    requestInfo: IRequestInfo,
    objs: any
  ): Promise<IHttpClientResponse>;
}

export interface IRequestHandlerWithoutAuth {
  prepareRequest(options: http.RequestOptions): void;
  canHandleAuthentication(response: IHttpClientResponse): false;
}

export type IRequestHandler =
  | IRequestHandlerWithAuth
  | IRequestHandlerWithoutAuth;

Notice how there are now two different kinds of authentication handlers: with and without auth. If a handler does not support authentication, it does not need to implement the handleAuthentication() method!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions