strapi-plugin-oidc 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/index.js +24 -10
- package/dist/server/index.mjs +24 -9
- package/package.json +2 -3
package/dist/server/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const axios = require("axios");
|
|
4
3
|
const node_crypto = require("node:crypto");
|
|
5
4
|
const pkceChallenge = require("pkce-challenge");
|
|
6
5
|
const strapiUtils = require("@strapi/utils");
|
|
7
6
|
const generator = require("generate-password");
|
|
8
7
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
9
|
-
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
10
8
|
const pkceChallenge__default = /* @__PURE__ */ _interopDefault(pkceChallenge);
|
|
11
9
|
const strapiUtils__default = /* @__PURE__ */ _interopDefault(strapiUtils);
|
|
12
10
|
const generator__default = /* @__PURE__ */ _interopDefault(generator);
|
|
@@ -163,23 +161,40 @@ async function oidcSignIn(ctx) {
|
|
|
163
161
|
ctx.set("Location", authorizationUrl);
|
|
164
162
|
return ctx.send({}, 302);
|
|
165
163
|
}
|
|
166
|
-
async function exchangeTokenAndFetchUserInfo(
|
|
167
|
-
const response = await
|
|
164
|
+
async function exchangeTokenAndFetchUserInfo(config2, params) {
|
|
165
|
+
const response = await fetch(config2.OIDC_TOKEN_ENDPOINT, {
|
|
166
|
+
method: "POST",
|
|
167
|
+
body: params,
|
|
168
168
|
headers: {
|
|
169
169
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
170
170
|
}
|
|
171
171
|
});
|
|
172
|
+
if (!response.ok) {
|
|
173
|
+
const errText = await response.text();
|
|
174
|
+
throw new Error(
|
|
175
|
+
`Failed to exchange token: ${response.status} ${response.statusText} - ${errText}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
const tokenData = await response.json();
|
|
172
179
|
let userInfoEndpointHeaders = {};
|
|
173
|
-
let userInfoEndpointParameters = `?access_token=${
|
|
180
|
+
let userInfoEndpointParameters = `?access_token=${tokenData.access_token}`;
|
|
174
181
|
if (config2.OIDC_USER_INFO_ENDPOINT_WITH_AUTH_HEADER) {
|
|
175
182
|
userInfoEndpointHeaders = {
|
|
176
|
-
|
|
183
|
+
Authorization: `Bearer ${tokenData.access_token}`
|
|
177
184
|
};
|
|
178
185
|
userInfoEndpointParameters = "";
|
|
179
186
|
}
|
|
180
187
|
const userInfoEndpoint = `${config2.OIDC_USER_INFO_ENDPOINT}${userInfoEndpointParameters}`;
|
|
181
|
-
const userResponse = await
|
|
182
|
-
|
|
188
|
+
const userResponse = await fetch(userInfoEndpoint, {
|
|
189
|
+
headers: userInfoEndpointHeaders
|
|
190
|
+
});
|
|
191
|
+
if (!userResponse.ok) {
|
|
192
|
+
const errText = await userResponse.text();
|
|
193
|
+
throw new Error(
|
|
194
|
+
`Failed to fetch user info: ${userResponse.status} ${userResponse.statusText} - ${errText}`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
return await userResponse.json();
|
|
183
198
|
}
|
|
184
199
|
async function registerNewUser(userService, oauthService2, roleService2, email, userResponseData, whitelistUser, config2, ctx) {
|
|
185
200
|
let roles2 = [];
|
|
@@ -225,7 +240,6 @@ async function handleUserAuthentication(userService, oauthService2, roleService2
|
|
|
225
240
|
}
|
|
226
241
|
async function oidcSignInCallback(ctx) {
|
|
227
242
|
const config2 = configValidation();
|
|
228
|
-
const httpClient = axios__default.default.create();
|
|
229
243
|
const userService = strapi.service("admin::user");
|
|
230
244
|
const oauthService2 = strapi.plugin("strapi-plugin-oidc").service("oauth");
|
|
231
245
|
const roleService2 = strapi.plugin("strapi-plugin-oidc").service("role");
|
|
@@ -244,7 +258,7 @@ async function oidcSignInCallback(ctx) {
|
|
|
244
258
|
params.append("grant_type", config2.OIDC_GRANT_TYPE);
|
|
245
259
|
params.append("code_verifier", ctx.session.codeVerifier);
|
|
246
260
|
try {
|
|
247
|
-
const userResponseData = await exchangeTokenAndFetchUserInfo(
|
|
261
|
+
const userResponseData = await exchangeTokenAndFetchUserInfo(config2, params);
|
|
248
262
|
const { activateUser, jwtToken } = await handleUserAuthentication(
|
|
249
263
|
userService,
|
|
250
264
|
oauthService2,
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
import { randomUUID, randomBytes } from "node:crypto";
|
|
3
2
|
import pkceChallenge from "pkce-challenge";
|
|
4
3
|
import strapiUtils from "@strapi/utils";
|
|
@@ -156,23 +155,40 @@ async function oidcSignIn(ctx) {
|
|
|
156
155
|
ctx.set("Location", authorizationUrl);
|
|
157
156
|
return ctx.send({}, 302);
|
|
158
157
|
}
|
|
159
|
-
async function exchangeTokenAndFetchUserInfo(
|
|
160
|
-
const response = await
|
|
158
|
+
async function exchangeTokenAndFetchUserInfo(config2, params) {
|
|
159
|
+
const response = await fetch(config2.OIDC_TOKEN_ENDPOINT, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
body: params,
|
|
161
162
|
headers: {
|
|
162
163
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
163
164
|
}
|
|
164
165
|
});
|
|
166
|
+
if (!response.ok) {
|
|
167
|
+
const errText = await response.text();
|
|
168
|
+
throw new Error(
|
|
169
|
+
`Failed to exchange token: ${response.status} ${response.statusText} - ${errText}`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
const tokenData = await response.json();
|
|
165
173
|
let userInfoEndpointHeaders = {};
|
|
166
|
-
let userInfoEndpointParameters = `?access_token=${
|
|
174
|
+
let userInfoEndpointParameters = `?access_token=${tokenData.access_token}`;
|
|
167
175
|
if (config2.OIDC_USER_INFO_ENDPOINT_WITH_AUTH_HEADER) {
|
|
168
176
|
userInfoEndpointHeaders = {
|
|
169
|
-
|
|
177
|
+
Authorization: `Bearer ${tokenData.access_token}`
|
|
170
178
|
};
|
|
171
179
|
userInfoEndpointParameters = "";
|
|
172
180
|
}
|
|
173
181
|
const userInfoEndpoint = `${config2.OIDC_USER_INFO_ENDPOINT}${userInfoEndpointParameters}`;
|
|
174
|
-
const userResponse = await
|
|
175
|
-
|
|
182
|
+
const userResponse = await fetch(userInfoEndpoint, {
|
|
183
|
+
headers: userInfoEndpointHeaders
|
|
184
|
+
});
|
|
185
|
+
if (!userResponse.ok) {
|
|
186
|
+
const errText = await userResponse.text();
|
|
187
|
+
throw new Error(
|
|
188
|
+
`Failed to fetch user info: ${userResponse.status} ${userResponse.statusText} - ${errText}`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
return await userResponse.json();
|
|
176
192
|
}
|
|
177
193
|
async function registerNewUser(userService, oauthService2, roleService2, email, userResponseData, whitelistUser, config2, ctx) {
|
|
178
194
|
let roles2 = [];
|
|
@@ -218,7 +234,6 @@ async function handleUserAuthentication(userService, oauthService2, roleService2
|
|
|
218
234
|
}
|
|
219
235
|
async function oidcSignInCallback(ctx) {
|
|
220
236
|
const config2 = configValidation();
|
|
221
|
-
const httpClient = axios.create();
|
|
222
237
|
const userService = strapi.service("admin::user");
|
|
223
238
|
const oauthService2 = strapi.plugin("strapi-plugin-oidc").service("oauth");
|
|
224
239
|
const roleService2 = strapi.plugin("strapi-plugin-oidc").service("role");
|
|
@@ -237,7 +252,7 @@ async function oidcSignInCallback(ctx) {
|
|
|
237
252
|
params.append("grant_type", config2.OIDC_GRANT_TYPE);
|
|
238
253
|
params.append("code_verifier", ctx.session.codeVerifier);
|
|
239
254
|
try {
|
|
240
|
-
const userResponseData = await exchangeTokenAndFetchUserInfo(
|
|
255
|
+
const userResponseData = await exchangeTokenAndFetchUserInfo(config2, params);
|
|
241
256
|
const { activateUser, jwtToken } = await handleUserAuthentication(
|
|
242
257
|
userService,
|
|
243
258
|
oauthService2,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-plugin-oidc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "A Strapi plugin that provides OpenID Connect (OIDC) authentication functionality for the Strapi Admin Panel.",
|
|
5
5
|
"strapi": {
|
|
6
6
|
"displayName": "OIDC Plugin",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"@strapi/design-system": "^2.2.0",
|
|
39
39
|
"@strapi/icons": "^2.2.0",
|
|
40
40
|
"@strapi/utils": "^5.41.1",
|
|
41
|
-
"axios": "^1.14.0",
|
|
42
41
|
"generate-password": "^1.7.1",
|
|
43
42
|
"pkce-challenge": "^6.0.0",
|
|
44
43
|
"react": "^18.3.1",
|
|
@@ -84,7 +83,7 @@
|
|
|
84
83
|
"globals": "^17.4.0",
|
|
85
84
|
"husky": "^9.1.7",
|
|
86
85
|
"lint-staged": "^16.4.0",
|
|
87
|
-
"msw": "^2.
|
|
86
|
+
"msw": "^2.13.0",
|
|
88
87
|
"prettier": "^3.8.1",
|
|
89
88
|
"supertest": "^7.2.2",
|
|
90
89
|
"typescript": "^5.9.3",
|