api-client/packages/hoppscotch-backend/src/auth/auth.controller.ts

230 lines
6.7 KiB
TypeScript
Raw Normal View History

import {
Body,
Controller,
Get,
Post,
Query,
Request,
Res,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { SignInMagicDto } from './dto/signin-magic.dto';
import { VerifyMagicDto } from './dto/verify-magic.dto';
2023-01-10 10:36:42 +00:00
import { Response } from 'express';
import * as E from 'fp-ts/Either';
import { RTJwtAuthGuard } from './guards/rt-jwt-auth.guard';
feat: Introducing Admin Module to Backend (HBE-83) (#21) * feat: introducing admin module, resolvers and service files as a module * feat: adding admin module in the app module * feat: introducing admin guard and decorator for allowing admin operations * feat: invited user model * chore: added user invitation mail description to mailer service * chore: added admin and user related error * feat: added invited users as a new model in prisma * chore: added admin related topics to pubsub * chore: added service method to fetch all users from user table * chore: added user deletion base implementation * Revert "chore: added user deletion base implementation" This reverts commit d1615ad83db2bae946e2d366a903d2f95051dabb. * feat: adding team related operations to admin * chore: adding admin related service methods to teams module service * chore: adding admin related service methods to team coll invitations requests envs * chore: added more module error messages * chore: added admin check service method * chore: added find individual user by UID in admin * HBE-106 feat: introduced code to handle first time admin login setup (#23) * test: wrote test cases for verifyAdmin route service method * chore: added comments to verifyAdmin service method * chore: deleted the prisma migration file * chore: added find admin users * feat: added user deletion into admin module * chore: admin user related errors * chore: fixed registry pattern in the shortcodes and teams to handle user deletion * chore: add subscription topic for user deletion * chore: updated user type in data handler * feat: implement and fix user deletion * feat: added make user admin mutation * chore: added unit tests for admin specific service methods in admin module * chore: added invitation not found error * chore: added admin specific operation test cases in specific modules * chore: added tests related to user deletion and admin related operation in user module * chore: updated to error constant when invitations not found * chore: fix rebase overwritten methods * feat: implement remove user as admin * chore: add new line * feat: introducing basic metrics into the self-hosted admin module (HBE-104) (#43) * feat: introducing admin module, resolvers and service files as a module * feat: adding admin module in the app module * feat: introducing admin guard and decorator for allowing admin operations * feat: invited user model * chore: added user invitation mail description to mailer service * chore: added admin and user related error * feat: added invited users as a new model in prisma * chore: added admin related topics to pubsub * chore: added service method to fetch all users from user table * chore: added user deletion base implementation * Revert "chore: added user deletion base implementation" This reverts commit d1615ad83db2bae946e2d366a903d2f95051dabb. * feat: adding team related operations to admin * chore: adding admin related service methods to teams module service * chore: adding admin related service methods to team coll invitations requests envs * chore: added more module error messages * chore: added admin check service method * chore: added find individual user by UID in admin * HBE-106 feat: introduced code to handle first time admin login setup (#23) * test: wrote test cases for verifyAdmin route service method * chore: added comments to verifyAdmin service method * chore: deleted the prisma migration file * chore: added find admin users * feat: added user deletion into admin module * chore: admin user related errors * chore: fixed registry pattern in the shortcodes and teams to handle user deletion * chore: add subscription topic for user deletion * chore: updated user type in data handler * feat: implement and fix user deletion * feat: added make user admin mutation * chore: added unit tests for admin specific service methods in admin module * chore: added invitation not found error * chore: added admin specific operation test cases in specific modules * chore: added tests related to user deletion and admin related operation in user module * chore: updated to error constant when invitations not found * chore: fix rebase overwritten methods * feat: implement remove user as admin * chore: add new line * chore: created new GQL return type for admin module * chore: created resolver and service method for method to fetch org metrics * chore: removed all entities relevant to seperate query for fetching admin metrics * chore: created all resolvers for metrics * feat: completed adding field resolves to query org metrics * test: wrote tests for all metrics related methods in admin module * test: added test cases for get count functions in multiple modules * chore: removed prisma migration folder * Delete backend-schema.gql * chore: resolved merge conflicts in team test file --------- Co-authored-by: ankitsridhar16 <ankit.sridhar16@gmail.com> * refactor: update mailer service to stop using postmark (#38) * refactor: update mailer service to stop using postmark * chore: remove postmark as a dep and move out postmark code * chore: remove postmark variables from .env.example * chore: add formal errors for mailer initialization errors * chore: add and update jsdoc comments in mailer service methods * chore: added user invitation mail description to mailer service * chore: updated with review changes requested for admin module * feat: adding admin resolver to gql schema * feat: adding input args for admin resolvers * chore: invited user renamed * chore: updated mailer service to be compatible with new mailer * chore: updated team service with review changes * chore: updated team collection service with review changes * chore: updated team environments service with review changes * chore: updated team requests service with review changes * chore: updated user service with review changes * refactor: invited user model * chore: review changes implemented * chore: implemented the review changes for admin, user and teams module * chore: removed error handling and implemented review changes * refactor: naming change for IsAdmin --------- Co-authored-by: Balu Babu <balub997@gmail.com> Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
2023-03-21 11:12:30 +00:00
import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { GqlUser } from 'src/decorators/gql-user.decorator';
import { AuthUser } from 'src/types/AuthUser';
import { RTCookie } from 'src/decorators/rt-cookie.decorator';
import { AuthProvider, authCookieHandler, authProviderCheck } from './helper';
import { GoogleSSOGuard } from './guards/google-sso.guard';
import { GithubSSOGuard } from './guards/github-sso.guard';
import { MicrosoftSSOGuard } from './guards/microsoft-sso-.guard';
import { ThrottlerBehindProxyGuard } from 'src/guards/throttler-behind-proxy.guard';
import { SkipThrottle } from '@nestjs/throttler';
import { AUTH_PROVIDER_NOT_SPECIFIED } from 'src/errors';
import { ConfigService } from '@nestjs/config';
import { throwHTTPErr } from 'src/utils';
import { UserLastLoginInterceptor } from 'src/interceptors/user-last-login.interceptor';
@UseGuards(ThrottlerBehindProxyGuard)
@Controller({ path: 'auth', version: '1' })
export class AuthController {
constructor(
private authService: AuthService,
private configService: ConfigService,
) {}
@Get('providers')
async getAuthProviders() {
const providers = await this.authService.getAuthProviders();
return { providers };
}
/**
** Route to initiate magic-link auth for a users email
*/
@Post('signin')
async signInMagicLink(
@Body() authData: SignInMagicDto,
@Query('origin') origin: string,
) {
if (
!authProviderCheck(
AuthProvider.EMAIL,
this.configService.get('INFRA.VITE_ALLOWED_AUTH_PROVIDERS'),
)
) {
throwHTTPErr({ message: AUTH_PROVIDER_NOT_SPECIFIED, statusCode: 404 });
}
const deviceIdToken = await this.authService.signInMagicLink(
authData.email,
origin,
);
if (E.isLeft(deviceIdToken)) throwHTTPErr(deviceIdToken.left);
return deviceIdToken.right;
}
2023-01-10 10:36:42 +00:00
/**
** Route to verify and sign in a valid user via magic-link
*/
2023-01-10 10:36:42 +00:00
@Post('verify')
async verify(@Body() data: VerifyMagicDto, @Res() res: Response) {
const authTokens = await this.authService.verifyMagicLinkTokens(data);
if (E.isLeft(authTokens)) throwHTTPErr(authTokens.left);
authCookieHandler(res, authTokens.right, false, null, this.configService);
2023-01-10 10:36:42 +00:00
}
/**
** Route to refresh auth tokens with Refresh Token Rotation
* @see https://auth0.com/docs/secure/tokens/refresh-tokens/refresh-token-rotation
*/
@Get('refresh')
@UseGuards(RTJwtAuthGuard)
async refresh(
@GqlUser() user: AuthUser,
@RTCookie() refresh_token: string,
@Res() res,
) {
const newTokenPair = await this.authService.refreshAuthTokens(
refresh_token,
user,
);
if (E.isLeft(newTokenPair)) throwHTTPErr(newTokenPair.left);
authCookieHandler(res, newTokenPair.right, false, null, this.configService);
}
2023-01-12 19:22:29 +00:00
/**
** Route to initiate SSO auth via Google
*/
2023-01-12 19:22:29 +00:00
@Get('google')
@UseGuards(GoogleSSOGuard)
2023-01-12 19:22:29 +00:00
async googleAuth(@Request() req) {}
/**
** Callback URL for Google SSO
* @see https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow#how-it-works
*/
2023-01-12 19:22:29 +00:00
@Get('google/callback')
@SkipThrottle()
@UseGuards(GoogleSSOGuard)
@UseInterceptors(UserLastLoginInterceptor)
2023-01-12 19:22:29 +00:00
async googleAuthRedirect(@Request() req, @Res() res) {
const authTokens = await this.authService.generateAuthTokens(req.user.uid);
2023-01-12 19:22:29 +00:00
if (E.isLeft(authTokens)) throwHTTPErr(authTokens.left);
authCookieHandler(
res,
authTokens.right,
true,
req.authInfo.state.redirect_uri,
this.configService,
);
2023-01-12 19:22:29 +00:00
}
2023-01-12 20:41:42 +00:00
/**
** Route to initiate SSO auth via Github
*/
2023-01-12 20:41:42 +00:00
@Get('github')
@UseGuards(GithubSSOGuard)
2023-01-12 20:41:42 +00:00
async githubAuth(@Request() req) {}
/**
** Callback URL for Github SSO
* @see https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow#how-it-works
*/
2023-01-12 20:41:42 +00:00
@Get('github/callback')
@SkipThrottle()
@UseGuards(GithubSSOGuard)
@UseInterceptors(UserLastLoginInterceptor)
2023-01-12 20:41:42 +00:00
async githubAuthRedirect(@Request() req, @Res() res) {
const authTokens = await this.authService.generateAuthTokens(req.user.uid);
2023-01-12 20:41:42 +00:00
if (E.isLeft(authTokens)) throwHTTPErr(authTokens.left);
authCookieHandler(
res,
authTokens.right,
true,
req.authInfo.state.redirect_uri,
this.configService,
);
2023-01-12 20:41:42 +00:00
}
/**
** Route to initiate SSO auth via Microsoft
*/
@Get('microsoft')
@UseGuards(MicrosoftSSOGuard)
async microsoftAuth(@Request() req) {}
/**
** Callback URL for Microsoft SSO
* @see https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow#how-it-works
*/
@Get('microsoft/callback')
@SkipThrottle()
@UseGuards(MicrosoftSSOGuard)
@UseInterceptors(UserLastLoginInterceptor)
async microsoftAuthRedirect(@Request() req, @Res() res) {
const authTokens = await this.authService.generateAuthTokens(req.user.uid);
if (E.isLeft(authTokens)) throwHTTPErr(authTokens.left);
authCookieHandler(
res,
authTokens.right,
true,
req.authInfo.state.redirect_uri,
this.configService,
);
}
/**
** Log user out by clearing cookies containing auth tokens
*/
@Get('logout')
async logout(@Res() res: Response) {
res.clearCookie('access_token');
res.clearCookie('refresh_token');
return res.status(200).send();
}
feat: Introducing Admin Module to Backend (HBE-83) (#21) * feat: introducing admin module, resolvers and service files as a module * feat: adding admin module in the app module * feat: introducing admin guard and decorator for allowing admin operations * feat: invited user model * chore: added user invitation mail description to mailer service * chore: added admin and user related error * feat: added invited users as a new model in prisma * chore: added admin related topics to pubsub * chore: added service method to fetch all users from user table * chore: added user deletion base implementation * Revert "chore: added user deletion base implementation" This reverts commit d1615ad83db2bae946e2d366a903d2f95051dabb. * feat: adding team related operations to admin * chore: adding admin related service methods to teams module service * chore: adding admin related service methods to team coll invitations requests envs * chore: added more module error messages * chore: added admin check service method * chore: added find individual user by UID in admin * HBE-106 feat: introduced code to handle first time admin login setup (#23) * test: wrote test cases for verifyAdmin route service method * chore: added comments to verifyAdmin service method * chore: deleted the prisma migration file * chore: added find admin users * feat: added user deletion into admin module * chore: admin user related errors * chore: fixed registry pattern in the shortcodes and teams to handle user deletion * chore: add subscription topic for user deletion * chore: updated user type in data handler * feat: implement and fix user deletion * feat: added make user admin mutation * chore: added unit tests for admin specific service methods in admin module * chore: added invitation not found error * chore: added admin specific operation test cases in specific modules * chore: added tests related to user deletion and admin related operation in user module * chore: updated to error constant when invitations not found * chore: fix rebase overwritten methods * feat: implement remove user as admin * chore: add new line * feat: introducing basic metrics into the self-hosted admin module (HBE-104) (#43) * feat: introducing admin module, resolvers and service files as a module * feat: adding admin module in the app module * feat: introducing admin guard and decorator for allowing admin operations * feat: invited user model * chore: added user invitation mail description to mailer service * chore: added admin and user related error * feat: added invited users as a new model in prisma * chore: added admin related topics to pubsub * chore: added service method to fetch all users from user table * chore: added user deletion base implementation * Revert "chore: added user deletion base implementation" This reverts commit d1615ad83db2bae946e2d366a903d2f95051dabb. * feat: adding team related operations to admin * chore: adding admin related service methods to teams module service * chore: adding admin related service methods to team coll invitations requests envs * chore: added more module error messages * chore: added admin check service method * chore: added find individual user by UID in admin * HBE-106 feat: introduced code to handle first time admin login setup (#23) * test: wrote test cases for verifyAdmin route service method * chore: added comments to verifyAdmin service method * chore: deleted the prisma migration file * chore: added find admin users * feat: added user deletion into admin module * chore: admin user related errors * chore: fixed registry pattern in the shortcodes and teams to handle user deletion * chore: add subscription topic for user deletion * chore: updated user type in data handler * feat: implement and fix user deletion * feat: added make user admin mutation * chore: added unit tests for admin specific service methods in admin module * chore: added invitation not found error * chore: added admin specific operation test cases in specific modules * chore: added tests related to user deletion and admin related operation in user module * chore: updated to error constant when invitations not found * chore: fix rebase overwritten methods * feat: implement remove user as admin * chore: add new line * chore: created new GQL return type for admin module * chore: created resolver and service method for method to fetch org metrics * chore: removed all entities relevant to seperate query for fetching admin metrics * chore: created all resolvers for metrics * feat: completed adding field resolves to query org metrics * test: wrote tests for all metrics related methods in admin module * test: added test cases for get count functions in multiple modules * chore: removed prisma migration folder * Delete backend-schema.gql * chore: resolved merge conflicts in team test file --------- Co-authored-by: ankitsridhar16 <ankit.sridhar16@gmail.com> * refactor: update mailer service to stop using postmark (#38) * refactor: update mailer service to stop using postmark * chore: remove postmark as a dep and move out postmark code * chore: remove postmark variables from .env.example * chore: add formal errors for mailer initialization errors * chore: add and update jsdoc comments in mailer service methods * chore: added user invitation mail description to mailer service * chore: updated with review changes requested for admin module * feat: adding admin resolver to gql schema * feat: adding input args for admin resolvers * chore: invited user renamed * chore: updated mailer service to be compatible with new mailer * chore: updated team service with review changes * chore: updated team collection service with review changes * chore: updated team environments service with review changes * chore: updated team requests service with review changes * chore: updated user service with review changes * refactor: invited user model * chore: review changes implemented * chore: implemented the review changes for admin, user and teams module * chore: removed error handling and implemented review changes * refactor: naming change for IsAdmin --------- Co-authored-by: Balu Babu <balub997@gmail.com> Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
2023-03-21 11:12:30 +00:00
@Get('verify/admin')
@UseGuards(JwtAuthGuard)
async verifyAdmin(@GqlUser() user: AuthUser) {
const userInfo = await this.authService.verifyAdmin(user);
if (E.isLeft(userInfo)) throwHTTPErr(userInfo.left);
return userInfo.right;
}
feat: platform independent core and the new desktop app (#4684) * feat(desktop): init * feat(desktop): external app download and setup * feat(desktop): offload app load to plugin system * perf(desktop): add rdbms facade and caching layer * feat: parallelize signing, shared trust, lru cache * feat: webapp encoder + compressor + hasher server * feat(desktop): app autoupdate with hashed loader * feat(kernel): init `hoppscotch-kernel` * feat(kernel): `io` * feat(kernel): `network` * feat(kernel): `network` - native interceptor * feat(kernel): `network` - interceptor - rest * feat(kernel): `network` - interceptor - graphql * feat(kernel): `network` - interceptor - capabilities * feat(kernel): `network` - interceptor - `FormData` * feat(kernel): `network` - interceptor - `oauth2.0` * feat(kernel): `store` * feat(desktop): dragging, traffic light, plugin workspaces * feat(kernel|wip): `store` * feat(kernel): `network` - capabilities - with active * feat(kernel|wip): `network` - interceptor - `proxy` * feat(kernel|wip): `network` - relay ext * feat(kernel): `network` - interceptor - `proxy` * feat(kernel): `network` - interceptor - decoding * feat(kernel): `network` - interceptor - Kernel Err * feat(kernel): `network` - flow transformation * feat(kernel): `network` - request status * fix(desktop): repositioning traffic lights on fullscreen exit * feat(kernel): `network` - interceptor - `agent` * feat(kernel): `store` - track updates * feat(kernel): `network` - interceptor - extension * feat(kernel): `network` - updates as overrides * feat(interceptor): pre-process request encoding * fix(ui): mismatched extension button size/position * feat(kernel): `network` - interceptor - `browser` * feat(native): common certs componsable * fix(kernel): interceptor selection store and json parse * feat(kernel): `network` - consistent multipart encoding * feat(kernel): `network` - interceptor - `OAuth2.0` * feat(kernel): `network` - interceptor - cookie support * feat(agent): registration list, log-sink, relay * feat(kernel): `network` - interceptor subtitles * feat(kernel): `store` - persist network settings * fix(agent): encrypted ser/de certificate requests * feat(kernel): `kernelInterceptor` spotlight service * fix(kernel): gql introspection edge-case schema * ref: conditionals for migrated components * feat(kernel): `localaccess` capability via relay * feat(kernel): `network` - explicit types and lint * feat(kernel): `store` - isolate host and platform * feat(kernel): `store` - persistence service * fix(infra): whitelisted origins, non-std engines * feat(desktop): impl deep-link callbacks * feat(kernel): `auth` * feat(kernel): `io` - event listeners * feat(kernel): platform migration * fix: dep `vue` import on Win 11 Fixes `error TS2305: Module '"vue"' has no exported member 'VueConstructor'.` arising from `splitpane` dependency. * fix(webapp-server): platform independent res paths * feat(desktop): auth and emit via embedded server * feat(platform): host, csp and bundle compatibility - Bundle name format for using as host - Windows UI handler HWND casting and version detection - CSP headers type handling in URI protocol - Protocol whitelist in env config * feat(desktop|wip): login flow with `auth-tokens` feat(desktop|wip): typesafe auth * feat(backend): `auth` token flow, gql/websocket feat(desktop): working auth for gql feat: gql client with refresh token * feat(backend): `auth` token flow, authorization bearer * fix(gen): qualifier clash when invalidating cache * feat(common): coordinated initialization service * fix(desktop): appload persistence in data json * feat(desktop|wip): desktop icons and updater * fix: typos in readme docs * fix: docker ignore copying on windows * fix: update `.lock` file after rebase * fix: `persistenceService` setup in tests * fix: remove old console logs * fix: console error on invalid schema Show console error if default value is used when loading invalid data from local storage * fix(test): `PersistenceService` methods * fix(test): `PersistenceService` rest tab state * fix(test): `PersistenceService` gql tab state * fix(test): `PersistenceService` global env * fix(test): `PersistenceService` mqtt request * fix(test): `PersistenceService` sse request * fix(test): `PersistenceService` socketio request * fix(test): `PersistenceService` websocket request * fix(test): `PersistenceService` secret environment * fix(test): `PersistenceService` selected env * fix(test): `PersistenceService` collections * fix(test): `PersistenceService` environments * fix(test): `PersistenceService` history * fix(test): `PersistenceService` settings * fix(test): `PersistenceService` migrations * fix(test): `InspectionService` request inspector * feat(desktop): button to clear bundle/key cache This is useful when there are partial updates to the web app or bundle gen server which haven't been correctly propagated when the app bundle was downloaded. If the user were to change the self host instance without updating the desktop app; which is possible albeit rarely under very certain circumstances, desktop app will refuse to load the bundle, this is because the desktop app cannot differentiate between partial updates vs incorrect bundle being hosted since both will fail verification. The button lets the user decide what should be the appropriate action, clear the bundle and trust the hosted app or make sure the app is built and hosted correctly. * fix(desktop): enforce one version per instance This was part of a leftover scaffolding from development. * fix(desktop): bundle url not stored after download * fix(desktop): stalling progress on updates * fix(backend): helper to parse cookie into kv-pairs * feat(desktop): launch session on working endpoints * fix(common): preserve `auth` structure and default * fix: loading native networking with kernel mode * fix: fallback for unhandled response error * fix: `urlencoded` content request processing * feat: `interceptor` - error mapping for `browser` * fix: backwards compatibility for `digest` auth * fix: platform check for `initializationService` * fix: `interceptor` - analytics `strategy` resolution * fix: `interceptor` - check for `cookies` component * fix: enable digest auth support for `native` * test: `interceptor` - kernel interceptor * fix(relay): `grantType` casing for OAuth2.0 * test(wip): kernel transformers * fix(relay): auth headers discarding others * fix(desktop): http version deserialization * fix(common): `grantType` extractor, auth processor * fix: `PersistenceService` - parsing edge cases * fix(infra): post rebase fixup * fix(web): component structure and lint * fix(desktop): cohesive splash opener, scroll url section * fix: explicit auto auth and docs on url auth * fix(relay): special chars failing proxy auth * fix: finer cert control setting option * fix: post-rebase fixup * feat(appload): ability to vendor pre-built bytes * fix: avoid copying over `target` dir in containers * fix: auth key missing in capability set * fix(desktop): relax `refresh_token` requirement This is to support Firebase token * fix(desktop): normalization for Windows WebView * feat(desktop): instance switcher and vendored app * fix(desktop): merge artifacts and conflicts * feat(desktop): instance switcher improvements * fix: derive instance name from normalized name * fix: pkg links, lints and UI edge cases * feat(desktop): restore window state after relaunch * fix(desktop): distinguish header for cloud/default * fix: instance switcher in web mode * fix: close dropdown on new instance modal * fix: whitelist vendored app origin * feat(desktop): platform parity - `collections` * fix: history entries population desync * fix(desktop): check for history storage status * fix(desktop): safe parse `globalEnv` * feat(desktop): platform parity - `environment` * fix: use settings store for proxy url * fix: lint, unused imports * fix: proxy input enabled for other interceptors * feat: reverse proxy for desktop app server * fix: duplicate entries after connecting to sh * fix: specify instance org qualified * fix: remove debugging logs * feat(desktop): enable `devtools` in release builds * fix(desktop): prepend protocol validation edgecase * feat(desktop): clear cache on removing instance * fix: better response toast message * fix: avoid reverse proxy for webapp server * fix(desktop): ignore subpath in instance name * feat: switcher ui/ux improvements * feat: more switcher ui/ux improvements * feat(server): specify bundle version at build time * fix(desktop): missing migration as rebase artifact * fix: minor switcher ui/ux improvement * fix: rebase artifacts * fix: consolidated toast on success * fix: missing i18n strings * fix(desktop): handle drag and drop fe side * feat: confirmation modal on instance removal * chore: minor UI update * chore: minor UI changes * fix: gql connection partial refactor * fix: resolve merge artifacts * chore: prod lint * feat(desktop): better desktop app update ux * fix: broken gql connection.ts --------- Co-authored-by: nivedin <nivedinp@gmail.com> Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
2025-02-27 18:31:25 +00:00
@Get('desktop')
@UseGuards(JwtAuthGuard)
@UseInterceptors(UserLastLoginInterceptor)
async desktopAuthCallback(
@GqlUser() user: AuthUser,
@Query('redirect_uri') redirectUri: string,
) {
if (!redirectUri || !redirectUri.startsWith('http://localhost')) {
throwHTTPErr({
message: 'Invalid desktop callback URL',
statusCode: 400,
feat: platform independent core and the new desktop app (#4684) * feat(desktop): init * feat(desktop): external app download and setup * feat(desktop): offload app load to plugin system * perf(desktop): add rdbms facade and caching layer * feat: parallelize signing, shared trust, lru cache * feat: webapp encoder + compressor + hasher server * feat(desktop): app autoupdate with hashed loader * feat(kernel): init `hoppscotch-kernel` * feat(kernel): `io` * feat(kernel): `network` * feat(kernel): `network` - native interceptor * feat(kernel): `network` - interceptor - rest * feat(kernel): `network` - interceptor - graphql * feat(kernel): `network` - interceptor - capabilities * feat(kernel): `network` - interceptor - `FormData` * feat(kernel): `network` - interceptor - `oauth2.0` * feat(kernel): `store` * feat(desktop): dragging, traffic light, plugin workspaces * feat(kernel|wip): `store` * feat(kernel): `network` - capabilities - with active * feat(kernel|wip): `network` - interceptor - `proxy` * feat(kernel|wip): `network` - relay ext * feat(kernel): `network` - interceptor - `proxy` * feat(kernel): `network` - interceptor - decoding * feat(kernel): `network` - interceptor - Kernel Err * feat(kernel): `network` - flow transformation * feat(kernel): `network` - request status * fix(desktop): repositioning traffic lights on fullscreen exit * feat(kernel): `network` - interceptor - `agent` * feat(kernel): `store` - track updates * feat(kernel): `network` - interceptor - extension * feat(kernel): `network` - updates as overrides * feat(interceptor): pre-process request encoding * fix(ui): mismatched extension button size/position * feat(kernel): `network` - interceptor - `browser` * feat(native): common certs componsable * fix(kernel): interceptor selection store and json parse * feat(kernel): `network` - consistent multipart encoding * feat(kernel): `network` - interceptor - `OAuth2.0` * feat(kernel): `network` - interceptor - cookie support * feat(agent): registration list, log-sink, relay * feat(kernel): `network` - interceptor subtitles * feat(kernel): `store` - persist network settings * fix(agent): encrypted ser/de certificate requests * feat(kernel): `kernelInterceptor` spotlight service * fix(kernel): gql introspection edge-case schema * ref: conditionals for migrated components * feat(kernel): `localaccess` capability via relay * feat(kernel): `network` - explicit types and lint * feat(kernel): `store` - isolate host and platform * feat(kernel): `store` - persistence service * fix(infra): whitelisted origins, non-std engines * feat(desktop): impl deep-link callbacks * feat(kernel): `auth` * feat(kernel): `io` - event listeners * feat(kernel): platform migration * fix: dep `vue` import on Win 11 Fixes `error TS2305: Module '"vue"' has no exported member 'VueConstructor'.` arising from `splitpane` dependency. * fix(webapp-server): platform independent res paths * feat(desktop): auth and emit via embedded server * feat(platform): host, csp and bundle compatibility - Bundle name format for using as host - Windows UI handler HWND casting and version detection - CSP headers type handling in URI protocol - Protocol whitelist in env config * feat(desktop|wip): login flow with `auth-tokens` feat(desktop|wip): typesafe auth * feat(backend): `auth` token flow, gql/websocket feat(desktop): working auth for gql feat: gql client with refresh token * feat(backend): `auth` token flow, authorization bearer * fix(gen): qualifier clash when invalidating cache * feat(common): coordinated initialization service * fix(desktop): appload persistence in data json * feat(desktop|wip): desktop icons and updater * fix: typos in readme docs * fix: docker ignore copying on windows * fix: update `.lock` file after rebase * fix: `persistenceService` setup in tests * fix: remove old console logs * fix: console error on invalid schema Show console error if default value is used when loading invalid data from local storage * fix(test): `PersistenceService` methods * fix(test): `PersistenceService` rest tab state * fix(test): `PersistenceService` gql tab state * fix(test): `PersistenceService` global env * fix(test): `PersistenceService` mqtt request * fix(test): `PersistenceService` sse request * fix(test): `PersistenceService` socketio request * fix(test): `PersistenceService` websocket request * fix(test): `PersistenceService` secret environment * fix(test): `PersistenceService` selected env * fix(test): `PersistenceService` collections * fix(test): `PersistenceService` environments * fix(test): `PersistenceService` history * fix(test): `PersistenceService` settings * fix(test): `PersistenceService` migrations * fix(test): `InspectionService` request inspector * feat(desktop): button to clear bundle/key cache This is useful when there are partial updates to the web app or bundle gen server which haven't been correctly propagated when the app bundle was downloaded. If the user were to change the self host instance without updating the desktop app; which is possible albeit rarely under very certain circumstances, desktop app will refuse to load the bundle, this is because the desktop app cannot differentiate between partial updates vs incorrect bundle being hosted since both will fail verification. The button lets the user decide what should be the appropriate action, clear the bundle and trust the hosted app or make sure the app is built and hosted correctly. * fix(desktop): enforce one version per instance This was part of a leftover scaffolding from development. * fix(desktop): bundle url not stored after download * fix(desktop): stalling progress on updates * fix(backend): helper to parse cookie into kv-pairs * feat(desktop): launch session on working endpoints * fix(common): preserve `auth` structure and default * fix: loading native networking with kernel mode * fix: fallback for unhandled response error * fix: `urlencoded` content request processing * feat: `interceptor` - error mapping for `browser` * fix: backwards compatibility for `digest` auth * fix: platform check for `initializationService` * fix: `interceptor` - analytics `strategy` resolution * fix: `interceptor` - check for `cookies` component * fix: enable digest auth support for `native` * test: `interceptor` - kernel interceptor * fix(relay): `grantType` casing for OAuth2.0 * test(wip): kernel transformers * fix(relay): auth headers discarding others * fix(desktop): http version deserialization * fix(common): `grantType` extractor, auth processor * fix: `PersistenceService` - parsing edge cases * fix(infra): post rebase fixup * fix(web): component structure and lint * fix(desktop): cohesive splash opener, scroll url section * fix: explicit auto auth and docs on url auth * fix(relay): special chars failing proxy auth * fix: finer cert control setting option * fix: post-rebase fixup * feat(appload): ability to vendor pre-built bytes * fix: avoid copying over `target` dir in containers * fix: auth key missing in capability set * fix(desktop): relax `refresh_token` requirement This is to support Firebase token * fix(desktop): normalization for Windows WebView * feat(desktop): instance switcher and vendored app * fix(desktop): merge artifacts and conflicts * feat(desktop): instance switcher improvements * fix: derive instance name from normalized name * fix: pkg links, lints and UI edge cases * feat(desktop): restore window state after relaunch * fix(desktop): distinguish header for cloud/default * fix: instance switcher in web mode * fix: close dropdown on new instance modal * fix: whitelist vendored app origin * feat(desktop): platform parity - `collections` * fix: history entries population desync * fix(desktop): check for history storage status * fix(desktop): safe parse `globalEnv` * feat(desktop): platform parity - `environment` * fix: use settings store for proxy url * fix: lint, unused imports * fix: proxy input enabled for other interceptors * feat: reverse proxy for desktop app server * fix: duplicate entries after connecting to sh * fix: specify instance org qualified * fix: remove debugging logs * feat(desktop): enable `devtools` in release builds * fix(desktop): prepend protocol validation edgecase * feat(desktop): clear cache on removing instance * fix: better response toast message * fix: avoid reverse proxy for webapp server * fix(desktop): ignore subpath in instance name * feat: switcher ui/ux improvements * feat: more switcher ui/ux improvements * feat(server): specify bundle version at build time * fix(desktop): missing migration as rebase artifact * fix: minor switcher ui/ux improvement * fix: rebase artifacts * fix: consolidated toast on success * fix: missing i18n strings * fix(desktop): handle drag and drop fe side * feat: confirmation modal on instance removal * chore: minor UI update * chore: minor UI changes * fix: gql connection partial refactor * fix: resolve merge artifacts * chore: prod lint * feat(desktop): better desktop app update ux * fix: broken gql connection.ts --------- Co-authored-by: nivedin <nivedinp@gmail.com> Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
2025-02-27 18:31:25 +00:00
});
}
const tokens = await this.authService.generateAuthTokens(user.uid);
if (E.isLeft(tokens)) throwHTTPErr(tokens.left);
return tokens.right;
}
@Get('verify-token')
@UseGuards(JwtAuthGuard)
async verifyToken(@GqlUser() user: AuthUser) {
return {
isValid: true,
uid: user.uid,
message: 'Token is valid',
};
}
}