Skip to content

Commit f8254c5

Browse files
authored
ci: update GitHub core actions to latest versions
Merge pull request #168 from node-oauth/ci-update-core-actions
1 parent 3a17e1b commit f8254c5

File tree

5 files changed

+129
-26
lines changed

5 files changed

+129
-26
lines changed

.github/workflows/tests-release.yml

+21-19
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ jobs:
2323
runs-on: ubuntu-latest
2424

2525
steps:
26-
- uses: actions/checkout@v2
27-
- uses: actions/setup-node@v2
26+
- uses: actions/checkout@v3
27+
- uses: actions/setup-node@v3
2828
with:
29-
node-version: '12'
30-
- run: npm audit --production # no audit for dev dependencies
29+
node-version: 16
30+
# install to create local package-lock.json but don't cache the files
31+
# also: no audit for dev dependencies
32+
- run: npm i --package-lock-only && npm audit --production
3133

3234
# STEP 2 - basic unit tests
3335

@@ -38,18 +40,18 @@ jobs:
3840
needs: [audit]
3941
strategy:
4042
matrix:
41-
node: [12, 14, 16]
43+
node: [14, 16, 18]
4244
steps:
4345
- name: Checkout ${{ matrix.node }}
44-
uses: actions/checkout@v2
46+
uses: actions/checkout@v3
4547

4648
- name: Setup node ${{ matrix.node }}
47-
uses: actions/setup-node@v2
49+
uses: actions/setup-node@v3
4850
with:
4951
node-version: ${{ matrix.node }}
5052

5153
- name: Cache dependencies ${{ matrix.node }}
52-
uses: actions/cache@v1
54+
uses: actions/cache@v3
5355
with:
5456
path: ~/.npm
5557
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
@@ -79,26 +81,26 @@ jobs:
7981
needs: [unittest]
8082
strategy:
8183
matrix:
82-
node: [12, 14] # TODO get running for node 16
84+
node: [14, 16, 18] # TODO get running for node 16+
8385
steps:
8486
# checkout this repo
8587
- name: Checkout ${{ matrix.node }}
86-
uses: actions/checkout@v2
88+
uses: actions/checkout@v3
8789

8890
# checkout express-adapter repo
8991
- name: Checkout express-adapter ${{ matrix.node }}
90-
uses: actions/checkout@v2
92+
uses: actions/checkout@v3
9193
with:
9294
repository: node-oauth/express-oauth-server
9395
path: github/testing/express
9496

9597
- name: Setup node ${{ matrix.node }}
96-
uses: actions/setup-node@v2
98+
uses: actions/setup-node@v3
9799
with:
98100
node-version: ${{ matrix.node }}
99101

100102
- name: Cache dependencies ${{ matrix.node }}
101-
uses: actions/cache@v1
103+
uses: actions/cache@v3
102104
with:
103105
path: ~/.npm
104106
key: ${{ runner.os }}-node-${{ matrix.node }}-node-oauth/express-oauth-server-${{ hashFiles('github/testing/express/**/package-lock.json') }}
@@ -120,10 +122,10 @@ jobs:
120122
runs-on: ubuntu-latest
121123
needs: [integrationtests]
122124
steps:
123-
- uses: actions/checkout@v2
124-
- uses: actions/setup-node@v2
125+
- uses: actions/checkout@v3
126+
- uses: actions/setup-node@v3
125127
with:
126-
node-version: 12
128+
node-version: 16
127129
registry-url: https://registry.npmjs.org/
128130
- run: npm i
129131
- run: npm publish --dry-run
@@ -137,11 +139,11 @@ jobs:
137139
contents: read
138140
packages: write
139141
steps:
140-
- uses: actions/checkout@v2
141-
- uses: actions/setup-node@v2
142+
- uses: actions/checkout@v3
143+
- uses: actions/setup-node@v3
142144
with:
143145
# we always publish targeting the lowest supported node version
144-
node-version: 12
146+
node-version: 16
145147
registry-url: $registry-url(npm)
146148
- run: npm i
147149
- run: npm publish --dry-run

.github/workflows/tests.yml

+27-4
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,46 @@ on:
1313
- release-* # on release we run an extended workflow so no need for this
1414

1515
jobs:
16+
lint:
17+
name: Javascript standard lint
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: checkout
21+
uses: actions/checkout@v3
22+
23+
- name: setup node
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: 16
27+
28+
- name: cache dependencies
29+
uses: actions/cache@v3
30+
with:
31+
path: ~/.npm
32+
key: ${{ runner.os }}-node-16-${{ hashFiles('**/package-lock.json') }}
33+
restore-keys: |
34+
${{ runner.os }}-node-
35+
- run: npm install
36+
- run: npm run lint
37+
1638
unittest:
1739
name: unit tests
1840
runs-on: ubuntu-latest
41+
needs: [lint]
1942
strategy:
2043
matrix:
21-
node: [12, 14, 16]
44+
node: [14, 16, 18]
2245
steps:
2346
- name: Checkout ${{ matrix.node }}
24-
uses: actions/checkout@v2
47+
uses: actions/checkout@v3
2548

2649
- name: Setup node ${{ matrix.node }}
27-
uses: actions/setup-node@v1
50+
uses: actions/setup-node@v3
2851
with:
2952
node-version: ${{ matrix.node }}
3053

3154
- name: Cache dependencies ${{ matrix.node }}
32-
uses: actions/cache@v1
55+
uses: actions/cache@v3
3356
with:
3457
path: ~/.npm
3558
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}

CHANGELOG.md

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
## Changelog
22

3+
## 4.2.0
4+
### Fixed
5+
- fix(core): Bearer regular expression matching in authenticate handler #105
6+
- fix(request): set WWW-Authenticate header for invalid requests #96 oauthjs#646
7+
- fix(handler): deny access when body.allowed is 'false' (#94)
8+
- fix(handlers): skip varcheck for state when allowEmptyState #89 #93
9+
10+
### Added
11+
- supported custom validateRedirectUri
12+
- feature: Supported state in case of denialMerge #99
13+
- Bearer regular expression matching in authenticate handler
14+
- docs: Update extension-grants.rst with example #92
15+
- feature(core): extract is.js into standalone package @node-oauth/formats #55
16+
- feature(authorize): allow custom implementations of validateRedirectUri via model #89 p.4
17+
- support custom validateRedirectUri()
18+
- allow to implement model.validateRedirectUri
19+
- updated AuthorizeHandler
20+
- default conforms with RFC 6819 Section-5.2.3.5
21+
22+
### Tests
23+
- Integration test password grant (#100)
24+
* test example
25+
* created db & model factories
26+
* added refresh_token grant type test
27+
* removed failing test, not implemented feature
28+
* add reference to issue
29+
* client authentication test
30+
* random client credentials in test
31+
* replace math.random by crypto.randomBytes
32+
33+
### CI
34+
- refactor(ci): remove unused ci workflow
35+
- fix(ci): use node-oauth/express-oauth-server for integration test
36+
337
## 4.1.1
438

539
### Added

docs/misc/extension-grants.rst

+45-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,51 @@
22
Extension Grants
33
==================
44

5-
.. todo:: Describe how to implement extension grants.
5+
Create a subclass of ``AbstractGrantType`` and create methods `handle` and `saveToken` along with other required methods according to your needs:
6+
7+
.. code-block:: js
8+
9+
const OAuth2Server = require('oauth2-server');
10+
const AbstractGrantType = OAuth2Server.AbstractGrantType;
11+
const InvalidArgumentError = OAuth2Server.InvalidArgumentError;
12+
const InvalidRequestError = OAuth2Server.InvalidRequestError;
13+
14+
class MyCustomGrantType extends AbstractGrantType {
15+
constructor(opts) {
16+
super(opts);
17+
}
18+
19+
async handle(request, client) {
20+
if (!request) throw new InvalidArgumentError('Missing `request`');
21+
if (!client) throw new InvalidArgumentError('Missing `client`');
22+
23+
let scope = this.getScope(request);
24+
let user = await this.getUserBySomething(request);
25+
26+
return this.saveToken(user, client, scope);
27+
}
28+
29+
async saveToken(user, client, scope) {
30+
this.validateScope(user, client, scope);
31+
32+
let token = {
33+
accessToken: await this.generateAccessToken(client, user, scope),
34+
accessTokenExpiresAt: this.getAccessTokenExpiresAt(),
35+
refreshToken: await this.generateRefreshToken(client, user, scope),
36+
refreshTokenExpiresAt: this.getRefreshTokenExpiresAt(),
37+
scope: scope
38+
};
39+
40+
return this.model.saveToken(token, client, user);
41+
}
42+
43+
async getUserBySomething(request) {
44+
//Get user's data by corresponding data (FB User ID, Google, etc.), etc.
45+
}
46+
}
47+
48+
module.exports = MyCustomGrantType;
649
750
Extension grants are registered through :ref:`OAuth2Server#token() <OAuth2Server#token>` (``options.extendedGrantTypes``).
851

52+
This might require you to approve the new ``grant_type`` for a particular ``client`` if you do checks on valid grant types.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@node-oauth/oauth2-server",
33
"description": "Complete, framework-agnostic, compliant and well tested module for implementing an OAuth2 Server in node.js",
4-
"version": "4.1.1",
4+
"version": "4.2.0",
55
"keywords": [
66
"oauth",
77
"oauth2"
@@ -35,7 +35,7 @@
3535
"eslint": "8.4.1",
3636
"mocha": "9.2.2",
3737
"nyc": "15.1.0",
38-
"sinon": "12.0.1"
38+
"sinon": "13.0.1"
3939
},
4040
"license": "MIT",
4141
"engines": {

0 commit comments

Comments
 (0)