π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: chatgpt enterprise domain restrictions
Nevo David267fd175d6c7
diff --git a/apps/backend/src/api/routes/oauth.controller.ts b/apps/backend/src/api/routes/oauth.controller.tsindex 080558f87..1d2c5e957 100644--- a/apps/backend/src/api/routes/oauth.controller.ts+++ b/apps/backend/src/api/routes/oauth.controller.ts@@ -2,6 +2,7 @@ import {Body,Controller,Get,+ Headers,HttpException,HttpStatus,Post,@@ -53,6 +54,16 @@ export class OAuthController {body.client_secret);}++ @Get('/userinfo')+ async userinfo(@Headers('authorization') authorization?: string) {+ return this._oauthService.getUserInfo(authorization);+ }++ @Post('/userinfo')+ async userinfoPost(@Headers('authorization') authorization?: string) {+ return this._oauthService.getUserInfo(authorization);+ }}@ApiTags('OAuth')diff --git a/libraries/nestjs-libraries/src/chat/start.mcp.ts b/libraries/nestjs-libraries/src/chat/start.mcp.tsindex fcc210bde..3167866b3 100644--- a/libraries/nestjs-libraries/src/chat/start.mcp.ts+++ b/libraries/nestjs-libraries/src/chat/start.mcp.ts@@ -17,6 +17,8 @@ const fixAcceptHeader = (req: Request) => {}};+const oauthScopes = ['openid', 'email', 'mcp:read', 'mcp:write'];+export const startMcp = async (app: INestApplication) => {const mastraService = app.get(MastraService, { strict: false });const organizationService = app.get(OrganizationService, { strict: false });@@ -77,6 +79,7 @@ export const startMcp = async (app: INestApplication) => {oauth: {resource: oauthResource,authorizationServers: [oauthResource],+ scopesSupported: oauthScopes,validateToken: async (token: string) => {const org = await resolveAuth(token);if (!org) {@@ -94,6 +97,7 @@ export const startMcp = async (app: INestApplication) => {oauth: {resource: claudeOauthResource,authorizationServers: [oauthResource],+ scopesSupported: oauthScopes,validateToken: async (token: string) => {const org = await resolveAuth(token);if (!org) {@@ -148,10 +152,43 @@ export const startMcp = async (app: INestApplication) => {issuer: oauthResource,authorization_endpoint: `${process.env.FRONTEND_URL}/oauth/authorize`,token_endpoint: `${process.env.NEXT_PUBLIC_OVERRIDE_BACKEND_URL || process.env.NEXT_PUBLIC_BACKEND_URL}/oauth/token`,+ userinfo_endpoint: `${process.env.NEXT_PUBLIC_OVERRIDE_BACKEND_URL || process.env.NEXT_PUBLIC_BACKEND_URL}/oauth/userinfo`,+ response_types_supported: ['code'],+ grant_types_supported: ['authorization_code'],+ token_endpoint_auth_methods_supported: ['client_secret_post'],+ code_challenge_methods_supported: ['S256'],+ scopes_supported: oauthScopes,+ });+ });++ app.use('/.well-known/openid-configuration', async (req: Request, res: Response, next: () => void) => {+ if (req.path !== '/mcp-oauth') {+ next();+ return;+ }++ res.setHeader('Access-Control-Allow-Origin', '*');+ if (req.method === 'OPTIONS') {+ res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type');+ res.writeHead(204);+ res.end();+ return;+ }+ res.setHeader('Content-Type', 'application/json');+ res.setHeader('Cache-Control', 'max-age=3600');+ res.json({+ issuer: oauthResource,+ authorization_endpoint: `${process.env.FRONTEND_URL}/oauth/authorize`,+ token_endpoint: `${process.env.NEXT_PUBLIC_OVERRIDE_BACKEND_URL || process.env.NEXT_PUBLIC_BACKEND_URL}/oauth/token`,+ userinfo_endpoint: `${process.env.NEXT_PUBLIC_OVERRIDE_BACKEND_URL || process.env.NEXT_PUBLIC_BACKEND_URL}/oauth/userinfo`,response_types_supported: ['code'],grant_types_supported: ['authorization_code'],+ token_endpoint_auth_methods_supported: ['client_secret_post'],code_challenge_methods_supported: ['S256'],- scopes_supported: ['mcp:read', 'mcp:write'],+ scopes_supported: oauthScopes,+ subject_types_supported: ['public'],+ claims_supported: ['sub', 'email', 'email_verified', 'name'],});});diff --git a/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.repository.ts b/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.repository.tsindex e3acf6c1f..ec899cdba 100644--- a/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.repository.ts+++ b/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.repository.ts@@ -200,7 +200,13 @@ export class OAuthRepository {},},user: {- select: { id: true },+ select: {+ id: true,+ email: true,+ name: true,+ lastName: true,+ activated: true,+ },},},});diff --git a/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts b/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.tsindex 2a1033dd4..1dd52b1e3 100644--- a/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts+++ b/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts@@ -4,6 +4,7 @@ import { CreateOAuthAppDto } from '@gitroom/nestjs-libraries/dtos/oauth/create-oimport { UpdateOAuthAppDto } from '@gitroom/nestjs-libraries/dtos/oauth/update-oauth-app.dto';import { makeId } from '@gitroom/nestjs-libraries/services/make.is';import { AuthService } from '@gitroom/helpers/auth/auth.service';+import { extractBearerToken } from '@gitroom/nestjs-libraries/chat/oauth-types';@Injectable()export class OAuthService {@@ -151,6 +152,7 @@ export class OAuthService {cus: paymentId,access_token: token,token_type: 'bearer',+ scope: 'openid email mcp:read mcp:write',};}@@ -159,6 +161,34 @@ export class OAuthService {return this._oauthRepository.findByAccessToken(encrypted);}+ async getUserInfo(authorization?: string) {+ const token = extractBearerToken(authorization);+ if (!token) {+ throw new HttpException(+ { error: 'invalid_token', error_description: 'Bearer token required' },+ HttpStatus.UNAUTHORIZED+ );+ }++ const authorizationRecord = await this.getOrgByOAuthToken(token);+ if (!authorizationRecord) {+ throw new HttpException(+ { error: 'invalid_token', error_description: 'Token is invalid or revoked' },+ HttpStatus.UNAUTHORIZED+ );+ }++ const { user } = authorizationRecord;+ return {+ sub: user.id,+ email: user.email,+ email_verified: user.activated,+ ...(user.name || user.lastName+ ? { name: [user.name, user.lastName].filter(Boolean).join(' ') }+ : {}),+ };+ }+async getApprovedApps(userId: string) {return this._oauthRepository.getApprovedApps(userId);}