Skip to content

Add the authentication strategy options (authStrategy, auth) and make the types for auth depend on what authStrategy is set to, either as part of the same options object or via .defaults() #18

@gr2m

Description

@gr2m

I made the show on the topic: gr2m/helpdesk#29

An approach that eventually worked: TypeScript playground

The goal here is

  1. If authStrategy is not set, require auth to be set to a string (token)

  2. If authStrategy is set, make sure it adheres to a common interface:

    • a synchronous "strategy" function, which returns an asynchrnous "auth" function
    • the returned "auth" function has a .hook property that can be used to hook into the request lifecycle
    • How authentication strategies work

    and derive the types for auth from the strategy function options

  3. Make it work for custom classes created with .withDefaults(), e.g.

    const AppOctokit = Octokit.defaults({ authStrategy: createAppAuth })
    const appOctokit = new AppOctokit()
    // ^ complains that `auth` must be set to `{ appId: string, privateKey: string, ... etc  }`

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions