panva / openid-client

OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
MIT License
1.83k stars 392 forks source link

TypeScript: Extending the Client class throws runtime exception #213

Closed yohanb closed 4 years ago

yohanb commented 4 years ago

Describe the bug

When using TypeScript, extending the class Client throws on runtime the error:

TypeError: Class extends value undefined is not a constructor or null

Seems to be related to a circular dependency issue when searching for similar issues.

To Reproduce Create extendedClient.ts with the following content:

import { Client, ClientMetadata } from "openid-client";

class ExtendedClient extends Client {

    constructor(metadata: ClientMetadata) {
        super(metadata);
    }
}

export default ExtendedClient;

Steps to reproduce the behaviour:

  1. tsc extendedClient.ts
  2. node extendedClient.js

Expected behaviour Being able to extend the client to provide custom functionality. For example, setting default metadata for a specific kind of flow:

class MsoDeviceCodeClient extends Client {

    constructor(metadata: ClientMetadata) {

        Object.assign(metadata, {
            response_types: ["code"],
            token_endpoint_auth_method: "none"
        });

        super(metadata);
    }
}

Environment:

Additional context N/A

panva commented 4 years ago

This is not how you get to the Client constructor, the types are incorrectly exporting the type like so. It’s present on an Issuer instance as a property. Please check the docs.