Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GitHub API authentication using a callback method

License

NotificationsYou must be signed in to change notification settings

octokit/auth-callback.js

Repository files navigation

GitHub API authentication using a callback method

@latestBuild Status

Usage

Browsers

Load@octokit/auth-callback directly fromesm.sh

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

Node

Install withnpm install @octokit/auth-callback

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

Important

As we useconditional exports, you will need to adapt yourtsconfig.json by setting"moduleResolution": "node16", "module": "node16".

See the TypeScript docs onpackage.json "exports".
See thishelpful guide on transitioning to ESM from@sindresorhus

lettoken;constauth=createCallbackAuth({callback:()=>token});awaitauth();// {//   type: 'unauthenticated'// }token="secret123";awaitauth();// {//   type: 'token',//   token: 'secret123',//   tokenType: 'oauth'// }

createCallbackAuth(options)

ThecreateCallbackAuth method accepts a singleoptions parameter

name type description
options.callbackfunctionRequired. A method that returns or resolves with a token string.

auth()

The asyncauth() method does not accept any arguments

Authentication object

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

  1. Unauthenticated if thecallback() returns or resolves a falsy value
  2. Token authentication if thecallback() returns or resolves with a string value

Unauthenticated

name type description
typestring"unauthenticated"

Token authentication

name type description
typestring"token"
tokenstring The personal access token
tokenTypestring

One of:

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

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

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

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

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

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

Or it can be passed as option torequest().

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

Contributing

SeeCONTRIBUTING.md

License

MIT

About

GitHub API authentication using a callback method

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors11


[8]ページ先頭

©2009-2025 Movatter.jp