0.0.13 • Published 2 years ago

oauth2-tester v0.0.13

Weekly downloads
13
License
MIT
Repository
github
Last release
2 years ago

OAuth2 Server Tester

Opinionated OAuth2 server tester. Very much a work in progress.

Currently building support for testing Authorization Code Grant Flow with PKCE.

Usage

import { AuthorizationCodeGrantTester } from 'oauth2-tester';
import { it, describe, before, after } from 'mocha'
import { step } from 'mocha-steps'
import { assert } from 'chai'

const serverRoot = 'http://localhost:3000'

const runners = new AuthorizationCodeGrantTester(
  {
    authorizationEndpoint: () => serverRoot + '/oauth2/authorize',
    tokenEndpoint: () => serverRoot + '/oauth2/token',
    availableScopes: () => ['read']
  },
  {
    clientGenerator,
    removeClient
  },
  {
    accountGenerator,
    registerAccount,
    removeAccount,
    login,
    consent
  }
)

const testFunctions = { describe, it, step, before, after, fail: assert.fail }
runners.register(testFunctions)

// Register tests for resources secured with OAuth
runners.registerResourceRequestTests(['exam:write'], testFunctions, [
  async requestWithAccessToken => {
    it('should create resource when POSTing', async () => {
      const res = await requestWithAccessToken({
        data: {},
        method: 'POST',
        url: serverRoot + '/resource/a'
      })
      ...
    })
  }
])

Debugging

The library uses the debug library for debug logging. To enable logging of authorization and access token request details, include oauth2-tester in the DEBUG environment variable.

The library uses axios to make HTTP requests and axios-debug-log to enable debugging of the requests. To enable logging of HTTP requests include axios in the DEBUG environment variable.

To enable debug logging of multiple libraries include the names in the DEBUG separated with spaces or commas e.g. DEBUG=axios,oauth2-tester. For further details refer to the debug library README.

0.0.13

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago