diff --git a/library.js b/library.js index 46c38d8..50bcf5a 100644 --- a/library.js +++ b/library.js @@ -11,7 +11,7 @@ const url = require('url'); const uid = require('uid2'); const async = require('async'); - const request = require('request-promise'); + const axios = require('axios'); const CustomStrategy = require('passport-custom'); const passport = module.parent.require('passport'); @@ -208,39 +208,38 @@ Oidc.getAccessTokenFromCode = async function (settings, code) { - const options = { - method: 'POST', - url: settings.tokenEndpoint, - form: { - grant_type: 'authorization_code', - client_id: settings.clientId, - client_secret: settings.clientSecret, - code: code, - redirect_uri: settings.callbackURL + const formData = new URLSearchParams({ + grant_type: 'authorization_code', + client_id: settings.clientId, + client_secret: settings.clientSecret, + code: code, + redirect_uri: settings.callbackURL + }); + + const response = await axios.post(settings.tokenEndpoint, formData, { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' } - } - return request(options); + }); + + return JSON.stringify(response.data); }; Oidc.getAccessTokenFromId = async function (settings, id) { const tokenUrl = new URL(settings.ssoTokenEndpoint); tokenUrl.searchParams.append("id", id); - const options = { - method: 'GET', - url: tokenUrl.href - } - return request(options); + + const response = await axios.get(tokenUrl.href); + return JSON.stringify(response.data); }; Oidc.getUserInfo = async function (settings, accessToken) { - const options = { - method: 'GET', - url: settings.userInfoEndpoint, + const response = await axios.get(settings.userInfoEndpoint, { headers: { 'Authorization': 'Bearer ' + accessToken } - } - return request(options); + }); + return JSON.stringify(response.data); }; /** diff --git a/package.json b/package.json index b270304..f764f55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodebb-plugin-sunbird-oidc", - "version": "1.0.17", + "version": "8.2.0", "description": "Authenticate to Sunbird identity provider.", "main": "library.js", "repository": { @@ -21,30 +21,28 @@ "license": "BSD-2-Clause", "readmeFilename": "README.md", "dependencies": { - "async": "^2", - "fs": "0.0.1-security", + "async": "^3.2.0", + "axios": "^1.7.0", "lodash": "^4.17.20", - "mongoose": "^5.11.9", + "mongoose": "^8.0.0", "passport-custom": "^1.1.1", - "request": "2.81.0", - "request-promise": "^4.2.6", "uid2": "0.0.x" }, "nbbpm": { - "compatibility": "^1.0.1" + "compatibility": "^4.0.0" }, "devDependencies": { - "@commitlint/cli": "^8.3.5", - "@commitlint/config-angular": "^8.3.4", + "@commitlint/cli": "^18.0.0", + "@commitlint/config-angular": "^18.0.0", "@types/async": "^3.0.8", "@types/express": "^4.17.3", "@types/passport-oauth2": "^1.4.8", - "eslint": "^6.8.0", + "eslint": "^8.57.0", "eslint-config-airbnb-base": "^14.1.0", "eslint-plugin-import": "^2.20.1", - "husky": "^4.2.3", - "lint-staged": "^10.0.8", - "typescript": "^3.8.3" + "husky": "^8.0.3", + "lint-staged": "^15.0.0", + "typescript": "^5.3.0" }, "husky": { "hooks": {} @@ -56,4 +54,4 @@ ] }, "scripts": {} -} +} \ No newline at end of file diff --git a/plugin.json b/plugin.json index 6d97d45..9f49c82 100644 --- a/plugin.json +++ b/plugin.json @@ -2,8 +2,7 @@ "id": "nodebb-plugin-sunbird-oidc", "name": "Sunbird SSO Plugin for NodeBB", "description": "Authenticate to Sunbird identity provider.", - "url": "https://github.com/vrayulu/nodebb-plugin-sunbird-oidc", - "library": "./library.js", + "url": "https://github.com/Sunbird-Lern/nodebb-plugin-sunbird-oidc", "templates": "templates", "hooks": [ {