Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #2127
gr2m opened this issue Aug 12, 2021 · 1 comment · Fixed by #19
Assignees
Labels
Type: Feature New feature or request typescript

Comments

@gr2m
Copy link
Contributor

gr2m commented Aug 12, 2021

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  }`
@github-actions
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant