Skip to content

Www authenticate #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
90d0049
Note we're now also seeking reviewers
thomseddon May 8, 2019
008dd7c
Update readme with link to v5-dev branch
thomseddon Jan 28, 2020
70f94d4
Add renovate.json
renovate-bot Jan 28, 2020
6c32d51
Add link to examples repo. Closes #571
thomseddon Jan 28, 2020
d8fbac7
Merge pull request #587 from oauthjs/renovate/configure
thomseddon Jan 28, 2020
a8a6460
Update dependency bluebird to v3.7.2
renovate-bot Jan 28, 2020
8580672
Update dependency jshint to v2.11.0
renovate-bot Jan 28, 2020
2443a56
Merge pull request #588 from oauthjs/renovate/bluebird-3.x
thomseddon Jan 28, 2020
56cea83
Merge pull request #589 from oauthjs/renovate/jshint-2.x
thomseddon Jan 28, 2020
d716fc3
Update dependency mocha to v3.5.3
renovate-bot Jan 28, 2020
6dfd257
Update dependency sinon to v2.4.1
renovate-bot Jan 28, 2020
4ca58d4
Update dependency statuses to v1.5.0
renovate-bot Jan 29, 2020
672870a
Update dependency basic-auth to v2
renovate-bot Jan 29, 2020
c4a8747
Update node versions
thomseddon Jan 28, 2020
fed558c
Bump lodash from 4.17.4 to 4.17.15
dependabot[bot] Jan 29, 2020
62e3fa8
Merge pull request #579 from oauthjs/dependabot/npm_and_yarn/lodash-4…
thomseddon Jan 29, 2020
125fa09
Merge pull request #591 from oauthjs/renovate/mocha-3.x
thomseddon Jan 29, 2020
c32f7a4
Merge pull request #592 from oauthjs/renovate/sinon-2.x
thomseddon Jan 29, 2020
dadce7d
Merge pull request #593 from oauthjs/renovate/statuses-1.x
thomseddon Jan 29, 2020
3344b9e
Update dependency type-is to v1.6.18
renovate-bot Jan 29, 2020
b0673df
Merge pull request #595 from oauthjs/renovate/basic-auth-2.x
thomseddon Jan 29, 2020
6fdf708
Update dependency should to v13
renovate-bot Jan 29, 2020
5f40f5c
Merge pull request #594 from oauthjs/renovate/type-is-1.x
thomseddon Jan 29, 2020
b53966c
Update dependency jshint to v2.11.1
renovate-bot May 15, 2020
5c3527d
Merge pull request #613 from oauthjs/renovate/jshint-2.x
thomseddon May 24, 2020
9b63ae9
Merge pull request #597 from oauthjs/renovate/should-13.x
thomseddon May 24, 2020
b84778b
Drop support for node 4/6/8 and add tests for 14
thomseddon May 24, 2020
0c3564d
Update dependency sinon to v9
renovate-bot May 24, 2020
be2e4a0
Update dependency mocha to v7
renovate-bot May 24, 2020
6997303
Merge pull request #602 from oauthjs/renovate/sinon-9.x
thomseddon May 24, 2020
cb2bb88
Merge pull request #596 from oauthjs/renovate/mocha-7.x
thomseddon May 24, 2020
e48a3ae
Release 3.0.2 🎉
thomseddon May 24, 2020
6cd573c
Merge pull request #616 from oauthjs/release/3.0.2
thomseddon May 24, 2020
5c7ea47
Release 3.0.2 🎉
thomseddon May 24, 2020
3dc1843
Merge pull request #617 from oauthjs/release/3.0.2
thomseddon May 24, 2020
40a5f99
Revert "Drop support for node 4/6/8 and add tests for 14"
thomseddon May 30, 2020
d9afa4d
Revert "Merge pull request #596 from oauthjs/renovate/mocha-7.x"
thomseddon May 30, 2020
8416f3a
Revert "Merge pull request #602 from oauthjs/renovate/sinon-9.x"
thomseddon May 30, 2020
30008b6
Bump mocha and sinon to lastest versions supporting node v4
thomseddon May 30, 2020
038ede0
Add testing for node v14
thomseddon May 30, 2020
2ee2fdc
Update readme with project status update
thomseddon May 30, 2020
b777883
Merge pull request #622 from oauthjs/fix/update-v3-strategy
thomseddon May 30, 2020
c823974
remove renovate in favour of dependabot
thomseddon Jun 11, 2020
0ee2fbe
Merge pull request #628 from oauthjs/fix/remove-renovate
thomseddon Jun 11, 2020
ee6c303
Add FUNDING.yml (#630)
thomseddon Jun 26, 2020
ae44d92
Updated .gitignore
mjsalinger Aug 17, 2018
9f94664
Changed 'hasOwnProperty' call in Request
Pritilender Sep 6, 2017
3ab54bd
Changed 'hasOwnProperty' call in Response
Pritilender Sep 6, 2017
7a01f87
set numArgs for promisify of generateAuthorizationCode
nkzawa Sep 8, 2017
e5792a5
readme: Update Slack badge and link
maxtruxa Sep 8, 2017
29125e3
fix: issue correct expiry dates for tokens #444
razvanz Sep 25, 2017
e3f8e18
Merge pull request #451 from razvanz/fix/validate-scope-on-authorize
mjsalinger Feb 13, 2018
88a6cd7
Merge pull request #491 from mattgrande/master
maxtruxa May 14, 2018
a2858cc
Merge pull request #471 from smartrecruiters/fix-migration-documentaiton
mjsalinger Aug 7, 2018
43e5925
Updated changelog
mjsalinger Aug 27, 2018
0ba47c2
Tag 3.1.0-rc1
thomseddon Jun 11, 2020
05e9eac
3.1.0 bump
thomseddon Jul 1, 2020
ac3bf3c
Bump lodash from 4.17.15 to 4.17.19
dependabot-preview[bot] Jul 9, 2020
0bbdcfe
v3.1.1 (#636)
thomseddon Jul 14, 2020
91d2cbe
Bump jshint from 2.11.1 to 2.12.0 (#640)
dependabot-preview[bot] Aug 6, 2020
e11930b
Set WWW-Authenticate header for invalid requests
Aug 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: thomseddon

31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,35 @@ node_modules/
docs/_build/
__pycache__/
*.pyc
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.iml

.idea
.jshint
.DS_Store

pids
logs
results

lib/dockerImage/keys
coverage
npm-debug.log*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ language: node_js

node_js:
- 4
- 4.0
- 6
- 6.0
- 7
- 7.0
- 8
- 8.0
- 10
- 12
- 13
- 14

sudo: false
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
## Changelog

### 3.0.0
### 3.1.0
* new: .npmignore tests
* fix: validate requested scope on authorize request
* fix: always issue correct expiry dates for tokens
* fix: set numArgs for promisify of generateAuthorizationCode
* fix: Changed 'hasOwnProperty' call in Response
* docs: Ensure accessTokenExpiresAt is required
* docs: Add missing notice of breaking change for accessExpireLifetime to migration guide
* docs: Correct tokens time scale for 2.x to 3.x migration guide
* readme: Update Slack badge and link
* readme: Fix link to RFC6750 standard

### 3.0.2 (24/05/2020)

* Update all dependencies 🎉

### 3.0.1 (27/08/2018)

* Doc fixes

Tag never released on npm

### 3.0.0 (04/08/2017)
* Complete re-write, with Promises and callback support
* Dropped support for node v0.8, v0.10, v0.12
* Supports Node v4, v6, v7, and v8. Will continue support for node current and active LTS versions
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This project is seeking maintainer(s)

## This is a popular project in need of maintenance, please contact @thomseddon on GitHub if you are interested in contributing to this project.

# oauth2-server

Expand All @@ -12,6 +9,7 @@

Complete, compliant and well tested module for implementing an OAuth2 server in [Node.js](https://nodejs.org).

Note: After a period of hiatus, this project is now back under active maintenance. Dependencies have been updated and bug fixes will land in v3 (current master). v4 will be _mostly backwards compatible_ with no code changes required for users using a supported node release. More details in [#621](https://github.com/oauthjs/node-oauth2-server/issues/621).

## Installation

Expand Down Expand Up @@ -40,7 +38,7 @@ The *oauth2-server* module is framework-agnostic but there are several officiall

Most users should refer to our [Express](https://github.com/oauthjs/express-oauth-server/tree/master/examples) or [Koa](https://github.com/oauthjs/koa-oauth-server/tree/master/examples) examples.

Examples for v3 are yet to be made.
More examples can be found here: https://github.com/14gasher/oauth-example

## Upgrading from 2.x

Expand All @@ -67,6 +65,6 @@ npm test
[travis-url]: https://travis-ci.org/oauthjs/node-oauth2-server
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg
[license-url]: https://raw.githubusercontent.com/oauthjs/node-oauth2-server/master/LICENSE
[slack-image]: https://img.shields.io/badge/slack-join-E01563.svg
[slack-url]: https://oauthjs.slack.com
[slack-image]: https://slack.oauthjs.org/badge.svg
[slack-url]: https://slack.oauthjs.org

18 changes: 9 additions & 9 deletions docs/misc/migrating-v2-to-v3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ The naming of the exposed middlewares has changed to match the OAuth2 _RFC_ more
Server options
--------------

The following server options can be set when instantiating the OAuth service:
The following server options can be set when instantiating the OAuth service:

* `addAcceptedScopesHeader`: **default true** Add the `X-Accepted-OAuth-Scopes` header with a list of scopes that will be accepted
* `addAuthorizedScopesHeader`: **default true** Add the `X-OAuth-Scopes` header with a list of scopes that the user is authorized for
* `allowBearerTokensInQueryString`: **default false** Determine if the bearer token can be included in the query string (i.e. `?access_token=`) for validation calls
* `allowEmptyState`: **default false** If true, `state` can be empty or not passed. If false, `state` is required.
* `authorizationCodeLifetime`: **default 300** Default number of milliseconds that the authorization code is active for
* `accessTokenLifetime`: **default 3600** Default number of milliseconds that an access token is valid for
* `refreshTokenLifetime`: **default 1209600** Default number of milliseconds that a refresh token is valid for
* `authorizationCodeLifetime`: **default 300** Default number of seconds that the authorization code is active for
* `accessTokenLifetime`: **default 3600** Default number of seconds that an access token is valid for
* `refreshTokenLifetime`: **default 1209600** Default number of seconds that a refresh token is valid for
* `allowExtendedTokenAttributes`: **default false** Allows additional attributes (such as `id_token`) to be included in token responses.
* `requireClientAuthentication`: **default true for all grant types** Allow ability to set client/secret authentication to `false` for a specific grant type.
* `requireClientAuthentication`: **default true for all grant types** Allow ability to set client/secret authentication to `false` for a specific grant type.

The following server options have changed behavior in v3.0.0:

Expand All @@ -60,7 +60,7 @@ Model specification
* `generateAuthorizationCode()` is **optional** and should return a `String`.
* `generateRefreshToken(client, user, scope)` is **optional** and should return a `String`.
* `getAccessToken(token)` should return an object with:

* `accessToken` (`String`)
* `accessTokenExpiresAt` (`Date`)
* `client` (`Object`), containing at least an `id` property that matches the supplied client
Expand All @@ -75,7 +75,7 @@ Model specification
* `user` (`Object`)

* `getClient(clientId, clientSecret)` should return an object with, at minimum:

* `redirectUris` (`Array`)
* `grants` (`Array`)

Expand All @@ -88,11 +88,11 @@ Model specification
* `user` (`Object`)

* `getUser(username, password)` should return an object:

* No longer requires that `id` be returned.

* `getUserFromClient(client)` should return an object:

* No longer requires that `id` be returned.

* `grantTypeAllowed()` was **removed**. You can instead:
Expand Down
2 changes: 1 addition & 1 deletion docs/model/spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ An ``Object`` representing the access token and associated data.
+------------------------------+--------+--------------------------------------------------+
| token.accessToken | String | The access token passed to ``getAccessToken()``. |
+------------------------------+--------+--------------------------------------------------+
| [token.accessTokenExpiresAt] | Date | The expiry time of the access token. |
| token.accessTokenExpiresAt | Date | The expiry time of the access token. |
+------------------------------+--------+--------------------------------------------------+
| [token.scope] | String | The authorized scope of the access token. |
+------------------------------+--------+--------------------------------------------------+
Expand Down
12 changes: 2 additions & 10 deletions lib/grant-types/abstract-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,15 @@ AbstractGrantType.prototype.generateRefreshToken = function(client, user, scope)
*/

AbstractGrantType.prototype.getAccessTokenExpiresAt = function() {
var expires = new Date();

expires.setSeconds(expires.getSeconds() + this.accessTokenLifetime);

return expires;
return new Date(Date.now() + this.accessTokenLifetime * 1000);
};

/**
* Get refresh token expiration date.
*/

AbstractGrantType.prototype.getRefreshTokenExpiresAt = function() {
var expires = new Date();

expires.setSeconds(expires.getSeconds() + this.refreshTokenLifetime);

return expires;
return new Date(Date.now() + this.refreshTokenLifetime * 1000);
};

/**
Expand Down
6 changes: 6 additions & 0 deletions lib/handlers/authenticate-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ AuthenticateHandler.prototype.handle = function(request, response) {
// @see https://tools.ietf.org/html/rfc6750#section-3.1
if (e instanceof UnauthorizedRequestError) {
response.set('WWW-Authenticate', 'Bearer realm="Service"');
} else if (e instanceof InvalidRequestError) {
response.set('WWW-Authenticate', 'Bearer realm="Service",error="invalid_request"');
} else if (e instanceof InvalidTokenError) {
response.set('WWW-Authenticate', 'Bearer realm="Service",error="invalid_token"');
} else if (e instanceof InsufficientScopeError) {
response.set('WWW-Authenticate', 'Bearer realm="Service",error="insufficient_scope"');
}

if (!(e instanceof OAuthError)) {
Expand Down
33 changes: 28 additions & 5 deletions lib/handlers/authorize-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,16 @@ AuthorizeHandler.prototype.handle = function(request, response) {
var ResponseType;

return Promise.bind(this)
.then(function() {
scope = this.getScope(request);
.then(function() {
var requestedScope = this.getScope(request);

return this.generateAuthorizationCode(client, user, scope);
})
return this.validateScope(user, client, requestedScope);
})
.then(function(validScope) {
scope = validScope;

return this.generateAuthorizationCode(client, user, scope);
})
.then(function(authorizationCode) {
state = this.getState(request);
ResponseType = this.getResponseType(request);
Expand Down Expand Up @@ -135,7 +140,7 @@ AuthorizeHandler.prototype.handle = function(request, response) {

AuthorizeHandler.prototype.generateAuthorizationCode = function(client, user, scope) {
if (this.model.generateAuthorizationCode) {
return promisify(this.model.generateAuthorizationCode).call(this.model, client, user, scope);
return promisify(this.model.generateAuthorizationCode, 3).call(this.model, client, user, scope);
}
return tokenUtil.generateRandomToken();
};
Expand Down Expand Up @@ -196,6 +201,24 @@ AuthorizeHandler.prototype.getClient = function(request) {
});
};

/**
* Validate requested scope.
*/
AuthorizeHandler.prototype.validateScope = function(user, client, scope) {
if (this.model.validateScope) {
return promisify(this.model.validateScope, 3).call(this.model, user, client, scope)
.then(function (scope) {
if (!scope) {
throw new InvalidScopeError('Invalid scope: Requested scope is invalid');
}

return scope;
});
} else {
return Promise.resolve(scope);
}
};

/**
* Get scope from the request.
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ function Request(options) {

// Store the headers in lower case.
for (var field in options.headers) {
if (options.headers.hasOwnProperty(field)) {
if (Object.prototype.hasOwnProperty.call(options.headers, field)) {
this.headers[field.toLowerCase()] = options.headers[field];
}
}

// Store additional properties of the request object passed in
for (var property in options) {
if (options.hasOwnProperty(property) && !this[property]) {
if (Object.prototype.hasOwnProperty.call(options, property) && !this[property]) {
this[property] = options[property];
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ function Response(options) {

// Store the headers in lower case.
for (var field in options.headers) {
if (options.headers.hasOwnProperty(field)) {
if (Object.prototype.hasOwnProperty.call(options.headers, field)) {
this.headers[field.toLowerCase()] = options.headers[field];
}
}

// Store additional properties of the response object passed in
for (var property in options) {
if (options.hasOwnProperty(property) && !this[property]) {
if (Object.prototype.hasOwnProperty.call(options, property) && !this[property]) {
this[property] = options[property];
}
}
Expand Down
Loading