Skip to content

Commit 169add7

Browse files
euanmillarnaftis
andauthored
Added CORS to allow client to communicate with mosip-api (#65)
* Added CORS and fixed schema on oidp user info url * Bump version * fix: cors * chore: no need to bump version in this case --------- Co-authored-by: naftis <pyry.rouvila@gmail.com>
1 parent 0cf1fa5 commit 169add7

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

packages/mosip-api/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"start": "NODE_ENV=production tsx src/index.ts"
88
},
99
"dependencies": {
10+
"@fastify/cors": "^10.1.0",
1011
"@fastify/formbody": "^8.0.1",
1112
"@fastify/swagger": "^9.2.0",
1213
"@fastify/swagger-ui": "^5.1.0",

packages/mosip-api/src/constants.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export const env = cleanEnv(process.env, {
55
PORT: port({ default: 2024 }),
66
HOST: str({ default: "0.0.0.0", devDefault: "localhost" }),
77
LOCALE: str({ devDefault: "en" }),
8+
DOMAIN: str({ devDefault: "*" }),
9+
CLIENT_APP_URL: url({ devDefault: 'http://localhost:3000/' }),
10+
COUNTRY_CONFIG_URL: url({ devDefault: 'http://localhost:3040' }),
811
OPENCRVS_GRAPHQL_GATEWAY_URL: str({
912
devDefault: "http://localhost:7070/graphql",
1013
desc: "The URL of the OpenCRVS GraphQL Gateway",

packages/mosip-api/src/esignet-api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const OIDPUserInfoSchema = z.object({
6868

6969
export const OIDPQuerySchema = z.object({
7070
code: z.string(),
71+
state: z.string(),
7172
});
7273

7374
export type OIDPUserInfoRequest = FastifyRequest<{

packages/mosip-api/src/index.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ import {
1111
} from "./routes/event-registration";
1212
import { env } from "./constants";
1313
import * as openapi from "./openapi-documentation";
14-
import { getOIDPUserInfo, OIDPUserInfoSchema } from "./esignet-api";
14+
import {
15+
getOIDPUserInfo,
16+
OIDPUserInfoSchema,
17+
OIDPQuerySchema,
18+
} from "./esignet-api";
1519
import formbody from "@fastify/formbody";
1620
import { reviewEventHandler } from "./routes/event-review";
21+
import cors from "@fastify/cors";
1722

1823
const envToLogger = {
1924
development: {
@@ -29,9 +34,15 @@ const envToLogger = {
2934
const app = Fastify({
3035
logger: envToLogger[env.isProd ? "production" : "development"],
3136
});
37+
3238
app.setValidatorCompiler(validatorCompiler);
3339
app.setSerializerCompiler(serializerCompiler);
3440
app.register(formbody);
41+
app.register(cors, {
42+
origin: [env.CLIENT_APP_URL],
43+
methods: ["GET", "POST", "OPTIONS"],
44+
allowedHeaders: ["Content-Type", "Authorization"],
45+
});
3546

3647
openapi.register(app);
3748

@@ -71,6 +82,7 @@ app.after(() => {
7182
handler: getOIDPUserInfo,
7283
schema: {
7384
body: OIDPUserInfoSchema,
85+
querystring: OIDPQuerySchema,
7486
},
7587
});
7688
});

yarn.lock

+24-18
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@
197197
ajv-formats "^3.0.1"
198198
fast-uri "^3.0.0"
199199

200+
"@fastify/cors@^10.1.0":
201+
version "10.1.0"
202+
resolved "https://registry.yarnpkg.com/@fastify/cors/-/cors-10.1.0.tgz#66170ea9698dd4ad7602b9a5382ad2dced878a26"
203+
integrity sha512-MZyBCBJtII60CU9Xme/iE4aEy8G7QpzGR8zkdXZkDFt7ElEMachbE61tfhAG/bvSaULlqlf0huMT12T7iqEmdQ==
204+
dependencies:
205+
fastify-plugin "^5.0.0"
206+
mnemonist "0.40.0"
207+
200208
"@fastify/error@^4.0.0":
201209
version "4.0.0"
202210
resolved "https://registry.yarnpkg.com/@fastify/error/-/error-4.0.0.tgz#7842d6161fbce78953638318be99033a0c2d5070"
@@ -1592,6 +1600,13 @@ minipass@^7.1.2:
15921600
resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.1.2.tgz#93a9626ce5e5e66bd4db86849e7515e92340a707"
15931601
integrity sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==
15941602

1603+
mnemonist@0.40.0:
1604+
version "0.40.0"
1605+
resolved "https://registry.yarnpkg.com/mnemonist/-/mnemonist-0.40.0.tgz#72e866d7f1e261d0c589717ff2bcfd6feb802db2"
1606+
integrity sha512-kdd8AFNig2AD5Rkih7EPCXhu/iMvwevQFX/uEiGhZyPZi7fHqOoF4V4kHLpCfysxXMgQ4B52kdPMCwARshKvEg==
1607+
dependencies:
1608+
obliterator "^2.0.4"
1609+
15951610
moment@^2.15.2:
15961611
version "2.30.1"
15971612
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
@@ -1624,6 +1639,11 @@ nodemailer@^6.9.16:
16241639
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.9.16.tgz#3ebdf6c6f477c571c0facb0727b33892635e0b8b"
16251640
integrity sha512-psAuZdTIRN08HKVd/E8ObdV6NO7NTBY3KsC30F7M4H1OnmLCUNaS56FpYxyb26zWLSyYF9Ozch9KYHhHegsiOQ==
16261641

1642+
obliterator@^2.0.4:
1643+
version "2.0.5"
1644+
resolved "https://registry.yarnpkg.com/obliterator/-/obliterator-2.0.5.tgz#031e0145354b0c18840336ae51d41e7d6d2c76aa"
1645+
integrity sha512-42CPE9AhahZRsMNslczq0ctAEtqk8Eka26QofnqC346BZdHDySk3LWka23LI7ULIw11NmltpiLagIq8gBozxTw==
1646+
16271647
on-exit-leak-free@^2.1.0:
16281648
version "2.1.2"
16291649
resolved "https://registry.yarnpkg.com/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz#fed195c9ebddb7d9e4c3842f93f281ac8dadd3b8"
@@ -1923,16 +1943,8 @@ statuses@2.0.1:
19231943
resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"
19241944
integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==
19251945

1926-
"string-width-cjs@npm:string-width@^4.2.0":
1927-
version "4.2.3"
1928-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1929-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
1930-
dependencies:
1931-
emoji-regex "^8.0.0"
1932-
is-fullwidth-code-point "^3.0.0"
1933-
strip-ansi "^6.0.1"
1934-
1935-
string-width@^4.1.0:
1946+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
1947+
name string-width-cjs
19361948
version "4.2.3"
19371949
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
19381950
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -1957,14 +1969,8 @@ string_decoder@^1.3.0:
19571969
dependencies:
19581970
safe-buffer "~5.2.0"
19591971

1960-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
1961-
version "6.0.1"
1962-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1963-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
1964-
dependencies:
1965-
ansi-regex "^5.0.1"
1966-
1967-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1972+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1973+
name strip-ansi-cjs
19681974
version "6.0.1"
19691975
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
19701976
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==

0 commit comments

Comments
 (0)