🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@octokit/auth-callback

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octokit/auth-callback

GitHub API authentication using a callback method

6.0.0
latest
Source
npm
Version published
Weekly downloads
7K
22.57%
Maintainers
1
Weekly downloads
 
Created
Source

auth-callback.js

GitHub API authentication using a callback method

@latest Build Status

Usage

Browsers

Load @octokit/auth-callback directly from esm.sh

<script type="module">
  import { createCallbackAuth } from "https://esm.sh/@octokit/auth-callback";
</script>

Node

Install with npm install @octokit/auth-callback

import { createCallbackAuth } from "@octokit/auth-callback";

[!IMPORTANT] As we use conditional exports, you will need to adapt your tsconfig.json by setting "moduleResolution": "node16", "module": "node16".

See the TypeScript docs on package.json "exports".
See this helpful guide on transitioning to ESM from @sindresorhus

let token;

const auth = createCallbackAuth({ callback: () => token });
await auth();
// {
//   type: 'unauthenticated'
// }
token = "secret123";
await auth();
// {
//   type: 'token',
//   token: 'secret123',
//   tokenType: 'oauth'
// }

createCallbackAuth(options)

The createCallbackAuth method accepts a single options parameter

name type description
options.callback function Required. A method that returns or resolves with a token string.

auth()

The async auth() method does not accept any arguments

Authentication object

The async auth() method resolves to one of two possible authentication objects

  • Unauthenticated if the callback() returns or resolves a falsy value
  • Token authentication if the callback() returns or resolves with a string value

Unauthenticated

name type description
type string "unauthenticated"

Token authentication

name type description
type string "token"
token string The personal access token
tokenType string

One of:

  • "oauth" (if returned string is an OAuth or personal access tokens)
  • "installation" (if returned string is an installation access tokens)
  • "app" (if returned string is a JSON Web Token (JWT) for GitHub App authentication)

auth.hook(request, route, parameters) or auth.hook(request, options)

auth.hook() hooks directly into the request life cycle. It amends the request to authenticate correctly based on the request URL.

The request option is an instance of @octokit/request. The route/options parameters are the same as for the request() method.

auth.hook() can be called directly to send an authenticated request

const { data: user } = await auth.hook(request, "GET /user");

Or it can be passed as option to request().

const requestWithAuth = request.defaults({
  request: {
    hook: auth.hook,
  },
});

const { data: user } = await requestWithAuth("GET /user");

Contributing

See CONTRIBUTING.md

License

MIT

Keywords

github

FAQs

Package last updated on 20 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts