From 3821ef624d81a078404c3560d059db3d55a5425a Mon Sep 17 00:00:00 2001 From: Francesco Stefanni Date: Sun, 28 Nov 2021 19:43:16 +0100 Subject: [PATCH 1/5] Updated doc for extension grants --- docs/misc/extension-grants.rst | 46 +++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/docs/misc/extension-grants.rst b/docs/misc/extension-grants.rst index 5d454d9..3bb67d4 100644 --- a/docs/misc/extension-grants.rst +++ b/docs/misc/extension-grants.rst @@ -2,7 +2,51 @@ Extension Grants ================== -.. todo:: Describe how to implement extension grants. +Create a subclass of ``AbstractGrantType`` and create methods `handle` and `saveToken` along with other required methods according to needs + +.. code-block:: js + + const OAuth2Server = require('oauth2-server'); + const AbstractGrantType = OAuth2Server.AbstractGrantType; + const InvalidArgumentError = OAuth2Server.InvalidArgumentError; + const InvalidRequestError = OAuth2Server.InvalidRequestError; + + class MyCustomGrantType extends AbstractGrantType { + constructor(opts) { + super(opts); + } + + async handle(request, client) { + if (!request) throw new InvalidArgumentError('Missing `request`'); + if (!client) throw new InvalidArgumentError('Missing `client`'); + + let scope = this.getScope(request); + let user = await this.getUserBySomething(request); + + return this.saveToken(user, client, scope); + } + + async saveToken(user, client, scope) { + this.validateScope(user, client, scope); + + let token = { + accessToken: await this.generateAccessToken(client, user, scope), + accessTokenExpiresAt: this.getAccessTokenExpiresAt(), + refreshToken: await this.generateRefreshToken(client, user, scope), + refreshTokenExpiresAt: this.getRefreshTokenExpiresAt(), + scope: scope + }; + + return this.model.saveToken(token, client, user); + } + + async getUserBySomething(request) { + //Get user's data by corresponding data (FB User ID, Google, etc.), etc. + } + } + + module.exports = MyCustomGrantType; Extension grants are registered through :ref:`OAuth2Server#token() ` (``options.extendedGrantTypes``). +This might require you to approve the new ``grant_type`` for a particular ``client`` if you do checks on valid grant types. From fff992d3fd4799b09d32051e0f616a62f7297f91 Mon Sep 17 00:00:00 2001 From: Francesco Stefanni <33950786+FStefanni@users.noreply.github.com> Date: Tue, 15 Mar 2022 20:09:51 +0100 Subject: [PATCH 2/5] Update package-lock.json --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index d9ecbca..a2a526e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@node-oauth/oauth2-server", - "version": "4.1.1", + "version": "4.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { From 937f22938e5b2107354a1a9340bd959291d1ade3 Mon Sep 17 00:00:00 2001 From: Francesco Stefanni <33950786+FStefanni@users.noreply.github.com> Date: Tue, 15 Mar 2022 20:10:26 +0100 Subject: [PATCH 3/5] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c043554..ae20a4b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@node-oauth/oauth2-server", "description": "Complete, framework-agnostic, compliant and well tested module for implementing an OAuth2 Server in node.js", - "version": "4.1.1", + "version": "4.1.0", "keywords": [ "oauth", "oauth2" From 6d2f653fb53c4a75aabb46af7da86e0bfc44600a Mon Sep 17 00:00:00 2001 From: Francesco Stefanni <33950786+FStefanni@users.noreply.github.com> Date: Tue, 15 Mar 2022 20:11:31 +0100 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e258b2a..668c19c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,5 @@ ## Changelog -## 4.1.1 - -### Added -- Added TypeScript types -### Changed -- Removed extra files when someone npm installs. -- Upgrades all code from ES5 to ES6, where possible. - ## 4.1.0 ### Changed * Bump dev dependencies to resolve vulnerabilities From 274a54dec0c565ab6c4515cb32ab3389f462417f Mon Sep 17 00:00:00 2001 From: Francesco Stefanni <33950786+FStefanni@users.noreply.github.com> Date: Wed, 30 Mar 2022 02:18:10 -0400 Subject: [PATCH 5/5] Update docs/misc/extension-grants.rst Co-authored-by: Uzlopak --- docs/misc/extension-grants.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/misc/extension-grants.rst b/docs/misc/extension-grants.rst index 3bb67d4..1fbe55a 100644 --- a/docs/misc/extension-grants.rst +++ b/docs/misc/extension-grants.rst @@ -2,7 +2,7 @@ Extension Grants ================== -Create a subclass of ``AbstractGrantType`` and create methods `handle` and `saveToken` along with other required methods according to needs +Create a subclass of ``AbstractGrantType`` and create methods `handle` and `saveToken` along with other required methods according to your needs: .. code-block:: js