jwtbutler 1.7.3 → 1.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +15 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -19,12 +19,12 @@ jwtbutler is a helper library for setting up a single sign on with jwt in a mult
19
19
 
20
20
  - a fully setup jwt auth server (like [simpleauth](https://github.com/vielhuber/simpleauth)) with the following routes
21
21
 
22
- | route | method | arguments | header | response |
23
- | -------- | ------ | -------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
- | /login | POST | email password | -- | `([ 'success' => true, 'message' => 'auth successful', 'public_message' => '...', 'data' => [ 'access_token' => '...', 'expires_in' => 3600, 'user_id' => 42 ] ], 200)` |
25
- | /refresh | POST | -- | Authorization: Bearer token | `([ 'success' => true, 'message' => 'auth successful', 'public_message' => '...', 'data' => [ 'access_token' => '...', 'expires_in' => 3600, 'user_id' => 42 ] ], 200)` |
26
- | /logout | POST | -- | Authorization: Bearer token | `([ 'success' => true, 'message' => 'logout successful', 'public_message' => '...' ], 200)` |
27
- | /check | POST | access_token | -- | `([ 'success' => true, 'message' => 'valid token', 'public_message' => '...', 'data' => [ 'expires_in' => 3600, 'user_id' => 42, 'client_id' => 7000000 ] ], 200)` |
22
+ | route | method | arguments | header | response |
23
+ | ------------- | ------ | -------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
+ | /auth/login | POST | email password | -- | `([ 'success' => true, 'message' => 'auth successful', 'public_message' => '...', 'data' => [ 'access_token' => '...', 'expires_in' => 3600, 'user_id' => 42 ] ], 200)` |
25
+ | /auth/refresh | POST | -- | Authorization: Bearer token | `([ 'success' => true, 'message' => 'auth successful', 'public_message' => '...', 'data' => [ 'access_token' => '...', 'expires_in' => 3600, 'user_id' => 42 ] ], 200)` |
26
+ | /auth/logout | POST | -- | Authorization: Bearer token | `([ 'success' => true, 'message' => 'logout successful', 'public_message' => '...' ], 200)` |
27
+ | /auth/check | POST | access_token | -- | `([ 'success' => true, 'message' => 'valid token', 'public_message' => '...', 'data' => [ 'expires_in' => 3600, 'user_id' => 42, 'client_id' => 7000000 ] ], 200)` |
28
28
 
29
29
  - 401 response code on bad authentication
30
30
 
@@ -50,7 +50,7 @@ now instantiate the object with the basic configuration:
50
50
 
51
51
  ```js
52
52
  const api = new jwtbutler({
53
- auth_server: 'https://example-auth-server.vielhuber.dev',
53
+ auth_server: 'https://example-auth-server.vielhuber.dev/auth',
54
54
  auth_login: 'email'
55
55
  });
56
56
  ```
@@ -212,8 +212,14 @@ if (@$_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
212
212
  }
213
213
 
214
214
  try {
215
+ $token = null;
216
+ if ($_SERVER['HTTP_AUTHORIZATION'] ?? '') {
217
+ $token = str_replace('Bearer ', '', $_SERVER['HTTP_AUTHORIZATION']);
218
+ } elseif ($_COOKIE['access_token'] ?? '') {
219
+ $token = str_replace('Bearer ', '', $_COOKIE['access_token']);
220
+ }
215
221
  $user_id = JWT::decode(
216
- str_replace('Bearer ', '', @$_SERVER['HTTP_AUTHORIZATION']), // access token
222
+ $token, // access token
217
223
  new Key('WM38tprPABEgkldbt2yTAgxf2CGstfr5', 'HS256'), // secret key
218
224
  )->sub;
219
225
  http_response_code(200);
@@ -248,7 +254,7 @@ RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
248
254
 
249
255
  setup the following vhosts:
250
256
 
251
- - https://example-auth-server.vielhuber.dev => jwt auth server (like [simpleauth](https://github.com/vielhuber/simpleauth))
257
+ - https://example-auth-server.vielhuber.dev/auth => jwt auth server (like [simpleauth](https://github.com/vielhuber/simpleauth))
252
258
  - https://example-auth-page1.vielhuber.dev => \_tests/page1
253
259
  - https://example-auth-page2.vielhuber.dev => \_tests/page2
254
260
  - https://example-auth-page3.vielhuber.dev => \_tests/page3
package/package.json CHANGED
@@ -84,7 +84,7 @@
84
84
  },
85
85
  "devDependencies": {},
86
86
  "name": "jwtbutler",
87
- "version": "1.7.3",
87
+ "version": "1.7.7",
88
88
  "description": "",
89
89
  "main": "_js/_build/script.js",
90
90
  "files": [