diff --git a/README.md b/README.md index 54b19da..e1dfffb 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,10 @@ list so other people can find it. $ npm install passport-oauth2 +## Publish package to cloudsmit +- Login to cloudsmith +- ```npm publish --access public``` + ## Usage #### Configure Strategy diff --git a/lib/strategy.js b/lib/strategy.js index 8575b72..04879e4 100644 --- a/lib/strategy.js +++ b/lib/strategy.js @@ -156,23 +156,28 @@ OAuth2Strategy.prototype.authenticate = function(req, options) { callbackURL: callbackURL } - if ((req.query && req.query.code) || (req.body && req.body.code)) { + if ((req.query && req.query.assertion) || (req.body && req.body.assertion)) { function loaded(err, ok, state) { if (err) { return self.error(err); } if (!ok) { return self.fail(state, 403); } - var code = (req.query && req.query.code) || (req.body && req.body.code); + var assertion = (req.query && req.query.assertion) || (req.body && req.body.assertion); var params = self.tokenParams(options); - params.grant_type = 'authorization_code'; + params.grant_type = 'urn:ietf:params:oauth:grant-type:jwt-bearer'; + params.assertion = assertion; + params.scope = self._scope.join(self._scopeSeparator); if (callbackURL) { params.redirect_uri = callbackURL; } if (typeof ok == 'string') { // PKCE params.code_verifier = ok; } + + var plainAuthorization = `${self._oauth2._clientId}:${self._oauth2._clientSecret}`; + self._oauth2._customHeaders['Authorization'] = `Basic ${btoa(plainAuthorization)}`; - self._oauth2.getOAuthAccessToken(code, params, + self._oauth2.getOAuthAccessToken(assertion, params, function(err, accessToken, refreshToken, params) { if (err) { return self.error(self._createOAuthError('Failed to obtain access token', err)); } if (!accessToken) { return self.error(new Error('Failed to obtain access token')); } @@ -426,4 +431,4 @@ OAuth2Strategy.prototype._createOAuthError = function(message, err) { // Expose constructor. -module.exports = OAuth2Strategy; +module.exports = OAuth2Strategy; \ No newline at end of file diff --git a/package.json b/package.json index 2805521..b375d4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "passport-oauth2", - "version": "1.7.0", + "name": "@myob/passport-oauth2", + "version": "1.8.1", "description": "OAuth 2.0 authentication strategy for Passport.", "keywords": [ "passport",