Skip to content

Commit

Permalink
fix(vars,),feat(mapi): fixed env var, started machine-to-machine api
Browse files Browse the repository at this point in the history
  • Loading branch information
finnc0 committed Jan 17, 2024
1 parent 7b8467d commit 9b7d007
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 13 deletions.
15 changes: 13 additions & 2 deletions apps/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ NEXT_PUBLIC_BASE_URL="" #// E.g. http://localhost:3000
COOKIESECRET='complex_password_at_least_32_characters_long'

# logto authorization / security

NEXT_PUBLIC_ID_RESOURCE_AUDIENCE="https://api.foo.bar/api"
NEXT_PUBLIC_ID_ISSUER=""
NEXT_PUBLIC_RESOURCE_AUDIENCE="https://api.foo.bar/api"
NEXT_PUBLIC_JWKS_ENDPOINT=https://localhost:3001/oidc/jwks

# Local Dev Stuff
Expand All @@ -24,3 +24,14 @@ NODE_TLS_REJECT_UNAUTHORIZED=0

# disable authentication verification (ONLY USE FOR TESTING PURPOSES)
#DISABLE_VERIFY_AUTH=0

APP_ID=""
APP_SECRET=""
ENDPOINT=""
BASE_URL=""
COOKIE_SECRET=""

MAPI_APP_ID=""
MAPI_APP_SECRET=""
MAPI_TOKEN_ENDPOINT=""
MAPI_RESOURCE_URI="https://default.logto.app/api"
6 changes: 6 additions & 0 deletions apps/app/additional.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ declare namespace NodeJS {
DATABASE_URL: string;
APP_ID: string;
APP_SECRET: string;
ENDPOINT: string;
BASE_URL: string;
NEXT_PUBLIC_BASE_URL: string;
COOKIE_SECRET: string;
MAPI_APP_ID: string;
MAPI_APP_SECRET: string;
MAPI_TOKEN_ENDPOINT: string;
MAPI_RESOURCE_URI: string;
NODE_ENV: string;
NEXT_PUBLIC_JWKS_ENDPOINT: string;
NEXT_PUBLIC_RESOURCE_AUDIENCE: string;
Expand Down
1 change: 1 addition & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"next-plausible": "^3.12.0",
"postcss": "^8.4.24",
"postcss-100vh-fix": "^1.0.2",
"qs": "^6.11.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
Expand Down
1 change: 0 additions & 1 deletion apps/app/server/trpc/router/gameplay/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const zodInput = z.object({
cheats: z.array(CheatTypes),
tsToken: z.string(),
});

const zodOutput = GameplaySchema;

export default rbacProtectedProcedure([
Expand Down
1 change: 0 additions & 1 deletion apps/app/server/trpc/router/site/getPageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { publicProcedure } from '../../trpc';
import { z } from 'zod';
import { serverSanitize } from '@utils/sanitize';
import { TRPCError } from '@trpc/server';

const zodInput = z
.object({
name: z.string(),
Expand Down
5 changes: 0 additions & 5 deletions packages/identity/.env.example

This file was deleted.

1 change: 1 addition & 0 deletions packages/identity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './utils/authUtils';
export type { V2Session } from './types/logto-auth';
export * from './logto/client';
export * as Scope from './rbac/scopes';
export * as Api from './logto/mapi/api';
4 changes: 3 additions & 1 deletion packages/identity/logto/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import LogtoClient from '@logto/next';
import { Scope } from '../index';
import * as Scope from '../rbac/scopes';
import 'dotenv/config';

export const logtoClient = new LogtoClient({
appId: process.env.APP_ID,
appSecret: process.env.APP_SECRET,
Expand Down
30 changes: 30 additions & 0 deletions packages/identity/logto/mapi/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import axios from 'axios';
import qs from 'qs';

const getApiAccessToken = async () => {
try {
const request = await axios.post(
process.env.MAPI_TOKEN_ENDPOINT,
qs.stringify({
grant_type: 'client_credentials',
resource: process.env.MAPI_RESOURCE_URI,
scope: 'all',
}),
{
auth: {
username: process.env.MAPI_APP_ID,
password: process.env.MAPI_APP_SECRET,
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
},
);
const response = await request.data;
return response;
} catch (error) {
return error;
}
};

export { getApiAccessToken };
3 changes: 2 additions & 1 deletion packages/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@logto/next": "^2.3.0",
"@types/node": "^20.10.8"
"@types/node": "^20.10.8",
"dotenv": "^16.3.1"
}
}
4 changes: 4 additions & 0 deletions packages/identity/process-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace NodeJS {
COOKIE_SECRET: string;
ENDPOINT: string;
BASE_URL: string;
MAPI_APP_ID: string;
MAPI_APP_SECRET: string;
MAPI_TOKEN_ENDPOINT: string;
MAPI_RESOURCE_URI: string;
NEXT_PUBLIC_RESOURCE_AUDIENCE: string;
}
}
2 changes: 1 addition & 1 deletion packages/identity/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "tsconfig/nextjs.json",
"extends": "tsconfig/base.json",
"include": ["./"],
"exclude": ["dist", "build", "node_modules"],
"compilerOptions": {}
Expand Down
6 changes: 5 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"NEXT_PUBLIC_ID_ISSUER",
"ENDPOINT",
"BASE_URL",
"SENTRY_RELEASE"
"SENTRY_RELEASE",
"MAPI_TOKEN_ENDPOINT",
"MAPI_APP_ID",
"MAPI_APP_SECRET",
"MAPI_RESOURCE_URI"
],
"outputs": ["dist/**", ".next/**", "out/**"]
},
Expand Down
18 changes: 18 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7437,6 +7437,13 @@ __metadata:
languageName: node
linkType: hard

"dotenv@npm:^16.3.1":
version: 16.3.1
resolution: "dotenv@npm:16.3.1"
checksum: 15d75e7279018f4bafd0ee9706593dd14455ddb71b3bcba9c52574460b7ccaf67d5cf8b2c08a5af1a9da6db36c956a04a1192b101ee102a3e0cf8817bbcf3dfd
languageName: node
linkType: hard

"dset@npm:^3.1.2":
version: 3.1.2
resolution: "dset@npm:3.1.2"
Expand Down Expand Up @@ -9975,6 +9982,7 @@ __metadata:
dependencies:
"@logto/next": ^2.3.0
"@types/node": ^20.10.8
dotenv: ^16.3.1
eslint-config-custom: "workspace:*"
tsconfig: "workspace:*"
languageName: unknown
Expand Down Expand Up @@ -13655,6 +13663,15 @@ __metadata:
languageName: node
linkType: hard

"qs@npm:^6.11.2":
version: 6.11.2
resolution: "qs@npm:6.11.2"
dependencies:
side-channel: ^1.0.4
checksum: e812f3c590b2262548647d62f1637b6989cc56656dc960b893fe2098d96e1bd633f36576f4cd7564dfbff9db42e17775884db96d846bebe4f37420d073ecdc0b
languageName: node
linkType: hard

"queue-microtask@npm:^1.2.2":
version: 1.2.3
resolution: "queue-microtask@npm:1.2.3"
Expand Down Expand Up @@ -16503,6 +16520,7 @@ __metadata:
next-plausible: ^3.12.0
postcss: ^8.4.33
postcss-100vh-fix: ^1.0.2
qs: ^6.11.2
react: ^18.2.0
react-dom: ^18.2.0
react-icons: ^4.12.0
Expand Down

0 comments on commit 9b7d007

Please sign in to comment.