- Notifications
You must be signed in to change notification settings - Fork5
GitHub API authentication using a callback method
License
octokit/auth-callback.js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
GitHub API authentication using a callback method
Browsers | Load <scripttype="module">import{createCallbackAuth}from"https://esm.sh/@octokit/auth-callback";</script> |
---|---|
Node | Install with 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'// }
ThecreateCallbackAuth
method accepts a singleoptions
parameter
name | type | description |
---|---|---|
options.callback | function | Required. A method that returns or resolves with a token string. |
The asyncauth()
method does not accept any arguments
The asyncauth()
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
name | type | description |
---|---|---|
type | string | "unauthenticated" |
name | type | description |
---|---|---|
type | string | "token" |
token | string | The personal access token |
tokenType | string | One of:
|
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");
About
GitHub API authentication using a callback method
Topics
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors11
Uh oh!
There was an error while loading.Please reload this page.