Skip to content

Commit

Permalink
feat: initial version (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored Nov 7, 2020
1 parent 2b0ce05 commit 0b5ab75
Show file tree
Hide file tree
Showing 14 changed files with 15,832 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release
on:
push:
branches:
- main

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run build
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.OCTOKITBOT_NPM_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node_version:
- 10
- 12
- 14

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install
run: npm ci
- name: Test
run: npm test
23 changes: 23 additions & 0 deletions .github/workflows/update-prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Update Prettier
on:
push:
branches:
- "dependabot/npm_and_yarn/prettier-*"
jobs:
update_prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
version: 12
- run: npm ci
- run: npm run lint:fix
- uses: gr2m/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
title: "Prettier updated"
body: "An update to prettier required updates to your code."
branch: ${{ github.ref }}
commit-message: "style: prettier"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
node_modules/
pkg/
191 changes: 189 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,196 @@
# 🚧 WORK IN PROGRESS. See [#1](https://github.com/octokit/auth-callback.js/pull/1)

# auth-callback.js

> GitHub API authentication using a callback method
[![@latest](https://img.shields.io/npm/v/@octokit/auth-callback.svg)](https://www.npmjs.com/package/@octokit/auth-callback)
[![Build Status](https://github.com/octokit/auth-callback.js/workflows/Test/badge.svg)](https://github.com/octokit/auth-callback.js/actions?query=workflow%3ATest+branch%3Amain)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=octokit/auth-callback.js)](https://dependabot.com/)

## Usage

<table>
<tbody valign=top align=left>
<tr><th>

Browsers

</th><td width=100%>

Load `@octokit/auth-callback` directly from [cdn.pika.dev](https://cdn.pika.dev)

```html
<script type="module">
import { createCallbackAuth } from "https://cdn.pika.dev/@octokit/auth-callback";
</script>
```

</td></tr>
<tr><th>

Node

</th><td>

Install with `npm install @octokit/auth-callback`

```js
const { createCallbackAuth } = require("@octokit/auth-callback");
```

</td></tr>
</tbody>
</table>

Use callback to rotate through a set of tokens.

```js
const tokens = ["token1", "token2"];

const auth = createCallbackAuth(() => {
const token = tokens.shift();
tokens.push(token);
return token;
});
await auth();
// {
// type: 'token',
// token: 'token1',
// tokenType: 'oauth'
// }
await auth();
// {
// type: 'token',
// token: 'token2',
// tokenType: 'oauth'
// }
await auth();
// {
// type: 'token',
// token: 'token1',
// tokenType: 'oauth'
// }
```

## `createCallbackAuth(callback)`

The `createCallbackAuth` method accepts a single `callback` parameter

<table width="100%">
<thead align=left>
<tr>
<th width=150>
name
</th>
<th width=70>
type
</th>
<th>
description
</th>
</tr>
</thead>
<tbody align=left valign=top>
<tr>
<th>
<code>callback</code>
</th>
<th>
<code>string</code>
</th>
<td>
<strong>Required</strong>. A method that returns or resolves with a token string.
</td>
</tr>
</tbody>
</table>

## `auth()`

The async `auth()` method does not accept any arguments

## Authentication object

<table width="100%">
<thead align=left>
<tr>
<th width=150>
name
</th>
<th width=70>
type
</th>
<th>
description
</th>
</tr>
</thead>
<tbody align=left valign=top>
<tr>
<th>
<code>type</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"token"</code>
</td>
</tr>
<tr>
<th>
<code>token</code>
</th>
<th>
<code>string</code>
</th>
<td>
The personal access token
</td>
</tr>
<tr>
<th>
<code>tokenType</code>
</th>
<th>
<code>string</code>
</th>
<td>

One of:

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

</td>
</tr>
</tbody>
</table>

## `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`](https://github.com/octokit/request.js#readme). The `route`/`options` parameters are the same as for the [`request()` method](https://github.com/octokit/request.js#request).

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

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

Or it can be passed as option to [`request()`](https://github.com/octokit/request.js#request).

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

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

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)
Expand Down
Loading

0 comments on commit 0b5ab75

Please sign in to comment.