pkce

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

README

xk6-oauth-pkce

xk6-oauth-pkce is a k6 extension provides the capability to generate OAuth PKCE code verifier and code challenge.

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Download xk6:
$ go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the k6 binary:
$ xk6 build --with github.com/frankhefeng/xk6-oauth-pkce@latest

Example

import pkce from "k6/x/oauth-pkce";

export default function () {
  const verifier = pkce.create("S256");
  console.log(verifier);
  console.log(verifier.verifier);
  console.log(verifier.challenge);
}

Result output:

./k6 run plain.js

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: plain.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] d4pvC50QvNMo9kpvxnWJWIBzst3LZlZVhA4bBhd1wGBwc7Qdvl4YErYx8XzOFHOt  source=console
INFO[0000] "PLAIN"                                       source=console
INFO[0000] d4pvC50QvNMo9kpvxnWJWIBzst3LZlZVhA4bBhd1wGBwc7Qdvl4YErYx8XzOFHOt  source=console

     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=171.26µs min=171.26µs med=171.26µs max=171.26µs p(90)=171.26µs p(95)=171.26µs
     iterations...........: 1   3703.703704/s


running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU
./k6 run s256.js

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: s256.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] {"verifier":"35UoJSej40X87vZLreSjUck3QfkjpvAw07aKOgwQY3FMjT2OfRG3G9aMdzkZhMtU","challenge_method":"S256","challenge":"HjKS897Yv8kjD5AX-s0mBsug4EzbjgiVSmUubkHNz58"}  source=console
INFO[0000] 35UoJSej40X87vZLreSjUck3QfkjpvAw07aKOgwQY3FMjT2OfRG3G9aMdzkZhMtU  source=console
INFO[0000] HjKS897Yv8kjD5AX-s0mBsug4EzbjgiVSmUubkHNz58   source=console

     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=250.45µs min=250.45µs med=250.45µs max=250.45µs p(90)=250.45µs p(95)=250.45µs
     iterations...........: 1   3003.003003/s


running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

Documentation

Index

Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeChallengeMethod

type CodeChallengeMethod string
const (
	CodeChallengePlain CodeChallengeMethod = "PLAIN"
	CodeChallengeS256                      = "S256"
)

type CodeVerifier

type CodeVerifier struct {
	Verifier        string
	ChallengeMethod CodeChallengeMethod
	Challenge       string
}

type ModuleInstance

type ModuleInstance struct {
	// contains filtered or unexported fields
}

ModuleInstance represents an instance of the OAuth PKCE module.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() k6modules.Exports

Exports returns the exports of the OAuth PKCE module so that it can be used in test scripts.

type OAuthPkceModule

type OAuthPkceModule struct {
	// contains filtered or unexported fields
}

OAuthPkceModule is the entrypoint into the OAuth PKCE module.

func (*OAuthPkceModule) Create

type RootModule

type RootModule struct{}

RootModule is the global module instance that will create module instances for each VU.

func New

func New() *RootModule

New returns a pointer to a new RootModule instance.

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance

NewModuleInstance implements the k6modules.Module interface to return a new instance for each VU.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL