All Projects → axa-group → Oauth2 Mock Server

axa-group / Oauth2 Mock Server

Licence: mit
A development and test oriented OAuth2 mock server

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Oauth2 Mock Server

Example Oauth2 Server
Example for OAuth 2 Server for Authlib.
Stars: ✭ 499 (+824.07%)
Mutual labels:  oauth2-server
Sharingan
Sharingan(写轮眼)是一个基于golang的流量录制回放工具,适合项目重构、回归测试等。
Stars: ✭ 617 (+1042.59%)
Mutual labels:  mock-server
Fake Oauth2 Server
An OAuth2 server implementation to be used for testing
Stars: ✭ 34 (-37.04%)
Mutual labels:  oauth2-server
Scala Oauth2 Provider
OAuth 2.0 server-side implementation written in Scala
Stars: ✭ 519 (+861.11%)
Mutual labels:  oauth2-server
Kakapo.js
🐦 Next generation mocking framework in Javascript
Stars: ✭ 535 (+890.74%)
Mutual labels:  mock-server
Easy Mock Server
A mock server for json and mock template files
Stars: ✭ 22 (-59.26%)
Mutual labels:  mock-server
Drakov
Mock Server that implements the API Blueprint specification
Stars: ✭ 467 (+764.81%)
Mutual labels:  mock-server
Mockserver Client Node
MockServer javascript client for browsers, Node.js or any grunt build
Stars: ✭ 52 (-3.7%)
Mutual labels:  mock-server
Fxtest
接口自动化测试平台——python+flask版,支持http协议,java 版本开发完毕https://github.com/liwanlei/plan
Stars: ✭ 564 (+944.44%)
Mutual labels:  mock-server
Oauth2 Shiro Jwt
use oauth2, shiro and spring specrity to make an ums system
Stars: ✭ 29 (-46.3%)
Mutual labels:  oauth2-server
Apisprout
Lightweight, blazing fast, cross-platform OpenAPI 3 mock server with validation
Stars: ✭ 519 (+861.11%)
Mutual labels:  mock-server
Doorkeeper
Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.
Stars: ✭ 4,917 (+9005.56%)
Mutual labels:  oauth2-server
Mock Server
Easy to use, no frills http mock server
Stars: ✭ 27 (-50%)
Mutual labels:  mock-server
Karate
Test Automation Made Simple
Stars: ✭ 5,497 (+10079.63%)
Mutual labels:  mock-server
Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (-29.63%)
Mutual labels:  mock-server
Puer Mock
Puer + Mock.js = A configurable mock server with configurable mock(random) data.
Stars: ✭ 497 (+820.37%)
Mutual labels:  mock-server
Atmo
✔️ Mock data for your prototypes and demos. Remote deployments to Zeit now.
Stars: ✭ 802 (+1385.19%)
Mutual labels:  mock-server
Mockstar
Demo project on How to be a Mockstar using Mockito and MockWebServer.
Stars: ✭ 53 (-1.85%)
Mutual labels:  mock-server
Oauth2 Server
OAuth2 Server Library
Stars: ✭ 42 (-22.22%)
Mutual labels:  oauth2-server
Web Framework For Java
A seed project with spring boot for AngularJS, AngularJs Material, Thymeleaf, RESTful API, MySQL and admin panel based on AdminLTE.
Stars: ✭ 29 (-46.3%)
Mutual labels:  oauth2-server

oauth2-mock-server

npm package Node.js version

OAuth 2 mock server. Intended to be used for development or testing purposes.

When developing an application that exposes or consumes APIs that are secured with an OAuth 2 authorization scheme, a mechanism for issuing access tokens is needed. Frequently, a developer needs to create custom code that fakes the creation of tokens for testing purposes, and these tokens cannot be properly verified, since there is no actual entity issuing those tokens.

The purpose of this package is to provide an easily configurable OAuth 2 server, that can be set up and teared down at will, and can be programatically run while performing automated tests.

Warning: This tool is not intended to be used as an actual OAuth 2 server. It lacks many features that would be required in a proper implementation.

Development prerequisites

How to use

Installation

Add it to your Node.js project as a development dependency:

With yarn...

yarn add -D oauth2-mock-server

...or with npm

npm install --save-dev oauth2-mock-server

Quickstart

Here is an example for creating and running a server instance with a single random RSA key:

const { OAuth2Server } = require('oauth2-mock-server');

let server = new OAuth2Server();

// Generate a new RSA key and add it to the keystore
await server.issuer.keys.generateRSA();

// Start the server
await server.start(8080, 'localhost');
console.log('Issuer URL:', server.issuer.url); // -> http://localhost:8080

// Do some work with the server
// ...

// Stop the server
await server.stop();

Any number of existing JSON-formatted or PEM-encoded keys can be added to the keystore:

// Add an existing JWK key to the keystore
await server.issuer.keys.add({
  kid: 'some-key',
  kty: 'RSA',
  // ...
});

// Add an existing PEM-encoded key to the keystore
const fs = require('fs');

let pemKey = fs.readFileSync('some-key.pem');
await server.issuer.keys.addPEM(pemKey, 'some-key');

JSON Web Tokens (JWT) can be built programmatically:

const request = require('request');

// Build a new token
let token = server.issuer.buildToken(true);

// Call a remote API with the token
request.get(
  'https://server.example.com/api/endpoint',
  { auth: { bearer: token } },
  function callback(err, res, body) {
    /* ... */
  }
);

Customization hooks

It also provides a convenient way, through event emitters, to programmatically customize the server processing. This is particularly useful when expecting the OIDC service to behave in a specific way on one single test:

  • The JWT access token

    // Modify the expiration time on next token produced
    service.once('beforeTokenSigning', (token, _req) => {
      const timestamp = Math.floor(Date.now() / 1000);
      token.payload.exp = timestamp + 400;
    });
    
    // Add the client ID to a token
    const basicAuth = require('basic-auth');
    service.once('beforeTokenSigning', (token, req) => {
      const credentials = basicAuth(req);
      const clientId = credentials ? credentials.name : req.body.client_id;
      token.payload.client_id = clientId;
    });
    
  • The token endpoint response body and status

    // Force the oidc service to provide an invalid_grant response on next call to the token endpoint
    service.once('beforeResponse', (tokenEndpointResponse, req) => {
      tokenEndpointResponse.body = {
        error: 'invalid_grant',
      };
      tokenEndpointResponse.statusCode = 400;
    });
    
  • The userinfo endpoint response body and status

    // Force the oidc service to provide an error on next call to userinfo endpoint
    service.once('beforeUserinfo', (userInfoResponse, req) => {
      userInfoResponse.body = {
        error: 'invalid_token',
        error_message: 'token is expired',
      };
      userInfoResponse.statusCode = 401;
    });
    
  • The revoke endpoint response body and status

    // Simulates a custom token revocation body
    service.once('beforeRevoke', (revokeResponse, req) => {
      revokeResponse.body = {
        result: 'revoked',
      };
    });
    
  • The authorization endpoint redirect uri and query parameters

    // Modify the uri and query parameters before the authorization redirect
    service.once('beforeAuthorizeRedirect', (authorizeRedirectUri, req) => {
      authorizeRedirectUri.url.searchParams.set('foo', 'bar');
    });
    

Supported endpoints

GET /.well-known/openid-configuration

Returns the OpenID Provider Configuration Information for the server.

GET /jwks

Returns the JSON Web Key Set (JWKS) of all the keys configured in the server.

POST /token

Issues access tokens. Currently, this endpoint is limited to:

  • No authentication
  • Client Credentials grant
  • Resource Owner Password Credentials grant
  • Authorization code grant
  • Refresh token grant

GET /authorize

It simulates the user authentication. It will automatically redirect to the callback endpoint sent as parameter. It currently supports only 'code' response_type.

GET /userinfo

It provides extra userinfo claims.

POST /revoke

It simulates a token revocation. This endpoint should always return 200 as stated by RFC 7009.

Command-Line Interface

The server can be run from the command line. You can either install it globally:

npm install -g oauth2-mock-server
oauth2-mock-server --help

or run it directly:

npx oauth2-mock-server --help

Attributions

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].