@@ -13,23 +13,14 @@ The purpose of this package is to provide an easily configurable OAuth 2 server,
1313
1414## Development prerequisites
1515
16- - [ Node.js 18+] ( https://nodejs.org/ )
17- - [ Yarn 1.15.2+] ( https://classic.yarnpkg.com/lang/en/ )
16+ - [ Node.js 20.19+] ( https://nodejs.org/ )
1817
1918## How to use
2019
2120### Installation
2221
2322Add it to your Node.js project as a development dependency:
2423
25- With yarn...
26-
27- ``` shell
28- yarn add -D oauth2-mock-server
29- ```
30-
31- ...or with npm
32-
3324``` shell
3425npm install --save-dev oauth2-mock-server
3526```
@@ -39,7 +30,9 @@ npm install --save-dev oauth2-mock-server
3930Here is an example for creating and running a server instance with a single random RSA key:
4031
4132``` js
42- const { OAuth2Server } = require (' oauth2-mock-server' );
33+ import { OAuth2Server } from ' oauth2-mock-server' ;
34+ // ...or in CommonJS style:
35+ // const { OAuth2Server } = require('oauth2-mock-server');
4336
4437let server = new OAuth2Server ();
4538
@@ -72,19 +65,24 @@ await server.issuer.keys.add({
7265JSON Web Tokens (JWT) can be built programmatically:
7366
7467``` js
75- const request = require ( ' request ' ) ;
68+ import axios from ' axios ' ;
7669
7770// Build a new token
7871let token = await server .issuer .buildToken ();
7972
8073// Call a remote API with the token
81- request .get (
82- ' https://server.example.com/api/endpoint' ,
83- { auth: { bearer: token } },
84- function callback (err , res , body ) {
74+ axios
75+ .get (' https://server.example.com/api/endpoint' , {
76+ headers: {
77+ authorization: ` Bearer ${ token} ` ,
78+ },
79+ })
80+ .then ((response ) => {
8581 /* ... */
86- }
87- );
82+ })
83+ .catch ((error ) => {
84+ /* ... */
85+ });
8886```
8987
9088### Supported grant types
@@ -97,12 +95,12 @@ request.get(
9795
9896### Supported JWK formats
9997
100- | Algorithm | kty | alg |
101- | ----------------- | --- | --------------------------- |
102- | RSASSA-PKCS1-v1_5 | RSA | RS256, RS384, RS512 |
103- | RSASSA-PSS | RSA | PS256, PS384, PS512 |
104- | ECDSA | EC | ES256, ES256K, ES384, ES512 |
105- | Edwards-curve DSA | OKP | EdDSA ( Ed25519 / Ed448) |
98+ | Algorithm | kty | alg |
99+ | ----------------- | --- | ------------------- |
100+ | RSASSA-PKCS1-v1_5 | RSA | RS256, RS384, RS512 |
101+ | RSASSA-PSS | RSA | PS256, PS384, PS512 |
102+ | ECDSA | EC | ES256, ES384, ES512 |
103+ | EdDSA | OKP | Ed25519 |
106104
107105### Customization hooks
108106
@@ -119,8 +117,9 @@ It also provides a convenient way, through event emitters, to programmatically c
119117 ```
120118
121119 ``` js
122- // Add the client ID to a token
123120 const basicAuth = require (' basic-auth' );
121+
122+ // Add the client ID to a token
124123 service .once (' beforeTokenSigning' , (token , req ) => {
125124 const credentials = basicAuth (req);
126125 const clientId = credentials ? credentials .name : req .body .client_id ;
0 commit comments