Browse Source

Merge c638df3218 into 9cad9e1027

pull/8471/merge
Ofri Peretz 3 days ago
committed by GitHub
parent
commit
b8e978f010
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 6
      apps/api/src/app/endpoints/auth/access-token-login.dto.ts
  3. 15
      apps/api/src/app/endpoints/auth/auth.controller.ts
  4. 12
      apps/api/src/app/endpoints/auth/verify-attestation.dto.ts
  5. 11
      apps/api/src/app/endpoints/auth/verify-authentication.dto.ts
  6. 10
      apps/api/src/app/endpoints/subscription/create-stripe-checkout-session.dto.ts
  7. 6
      apps/api/src/app/endpoints/subscription/redeem-coupon.dto.ts
  8. 7
      apps/api/src/app/endpoints/subscription/subscription.controller.ts

1
CHANGELOG.md

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Improved the validation of the request bodies in the authentication and subscription endpoints
- Upgraded `dotenv` from version `18.0.9` to `18.0.10` - Upgraded `dotenv` from version `18.0.9` to `18.0.10`
- Upgraded `ng-extract-i18n-merge` from version `3.4.0` to `3.5.0` - Upgraded `ng-extract-i18n-merge` from version `3.4.0` to `3.5.0`
- Upgraded `prisma` from version `7.10.0` to `7.10.1` - Upgraded `prisma` from version `7.10.0` to `7.10.1`

6
apps/api/src/app/endpoints/auth/access-token-login.dto.ts

@ -0,0 +1,6 @@
import { IsString } from 'class-validator';
export class AccessTokenLoginDto {
@IsString()
accessToken: string;
}

15
apps/api/src/app/endpoints/auth/auth.controller.ts

@ -5,11 +5,7 @@ import { OAuthCallbackGuard } from '@ghostfolio/api/guards/oauth-callback.guard'
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
import { DEFAULT_LANGUAGE_CODE } from '@ghostfolio/common/config'; import { DEFAULT_LANGUAGE_CODE } from '@ghostfolio/common/config';
import { AuthDeviceDto } from '@ghostfolio/common/dtos'; import { AuthDeviceDto } from '@ghostfolio/common/dtos';
import { import { OAuthResponse } from '@ghostfolio/common/interfaces';
AssertionCredentialJSON,
AttestationCredentialJSON,
OAuthResponse
} from '@ghostfolio/common/interfaces';
import { import {
Body, Body,
@ -31,8 +27,11 @@ import type {
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { getReasonPhrase, StatusCodes } from 'http-status-codes'; import { getReasonPhrase, StatusCodes } from 'http-status-codes';
import { AccessTokenLoginDto } from './access-token-login.dto';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { GenerateAuthenticationOptionsDto } from './generate-authentication-options.dto'; import { GenerateAuthenticationOptionsDto } from './generate-authentication-options.dto';
import { VerifyAttestationDto } from './verify-attestation.dto';
import { VerifyAuthenticationDto } from './verify-authentication.dto';
import { WebAuthService } from './web-auth.service'; import { WebAuthService } from './web-auth.service';
@AllowDuringImpersonation() @AllowDuringImpersonation()
@ -47,7 +46,7 @@ export class AuthController {
@Post('anonymous') @Post('anonymous')
@UseGuards(CustomThrottlerGuard) @UseGuards(CustomThrottlerGuard)
public async accessTokenLogin( public async accessTokenLogin(
@Body() body: { accessToken: string } @Body() body: AccessTokenLoginDto
): Promise<OAuthResponse> { ): Promise<OAuthResponse> {
try { try {
const authToken = await this.authService.validateAnonymousLogin( const authToken = await this.authService.validateAnonymousLogin(
@ -142,7 +141,7 @@ export class AuthController {
@Post('webauthn/verify-attestation') @Post('webauthn/verify-attestation')
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) @UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async verifyAttestation( public async verifyAttestation(
@Body() body: { deviceName: string; credential: AttestationCredentialJSON } @Body() body: VerifyAttestationDto
): Promise<AuthDeviceDto> { ): Promise<AuthDeviceDto> {
return this.webAuthService.verifyAttestation(body.credential); return this.webAuthService.verifyAttestation(body.credential);
} }
@ -150,7 +149,7 @@ export class AuthController {
@Post('webauthn/verify-authentication') @Post('webauthn/verify-authentication')
@UseGuards(CustomThrottlerGuard) @UseGuards(CustomThrottlerGuard)
public async verifyAuthentication( public async verifyAuthentication(
@Body() body: { deviceId: string; credential: AssertionCredentialJSON } @Body() body: VerifyAuthenticationDto
): Promise<OAuthResponse> { ): Promise<OAuthResponse> {
try { try {
const authToken = await this.webAuthService.verifyAuthentication( const authToken = await this.webAuthService.verifyAuthentication(

12
apps/api/src/app/endpoints/auth/verify-attestation.dto.ts

@ -0,0 +1,12 @@
import type { AttestationCredentialJSON } from '@ghostfolio/common/interfaces';
import { IsObject, IsOptional, IsString } from 'class-validator';
export class VerifyAttestationDto {
@IsObject()
credential: AttestationCredentialJSON;
@IsOptional()
@IsString()
deviceName?: string;
}

11
apps/api/src/app/endpoints/auth/verify-authentication.dto.ts

@ -0,0 +1,11 @@
import type { AssertionCredentialJSON } from '@ghostfolio/common/interfaces';
import { IsObject, IsString } from 'class-validator';
export class VerifyAuthenticationDto {
@IsObject()
credential: AssertionCredentialJSON;
@IsString()
deviceId: string;
}

10
apps/api/src/app/endpoints/subscription/create-stripe-checkout-session.dto.ts

@ -0,0 +1,10 @@
import { IsOptional, IsString } from 'class-validator';
export class CreateStripeCheckoutSessionDto {
@IsOptional()
@IsString()
couponId?: string;
@IsString()
priceId: string;
}

6
apps/api/src/app/endpoints/subscription/redeem-coupon.dto.ts

@ -0,0 +1,6 @@
import { IsString } from 'class-validator';
export class RedeemCouponDto {
@IsString()
couponCode: string;
}

7
apps/api/src/app/endpoints/subscription/subscription.controller.ts

@ -33,6 +33,9 @@ import { AuthGuard } from '@nestjs/passport';
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; import { StatusCodes, getReasonPhrase } from 'http-status-codes';
import { CreateStripeCheckoutSessionDto } from './create-stripe-checkout-session.dto';
import { RedeemCouponDto } from './redeem-coupon.dto';
@AllowDuringImpersonation() @AllowDuringImpersonation()
@Controller('subscription') @Controller('subscription')
export class SubscriptionController { export class SubscriptionController {
@ -49,7 +52,7 @@ export class SubscriptionController {
@HttpCode(StatusCodes.OK) @HttpCode(StatusCodes.OK)
@UseGuards(AuthGuard('jwt'), CustomThrottlerGuard, HasPermissionGuard) @UseGuards(AuthGuard('jwt'), CustomThrottlerGuard, HasPermissionGuard)
public async redeemCoupon( public async redeemCoupon(
@Body() { couponCode }: { couponCode: string } @Body() { couponCode }: RedeemCouponDto
): Promise<RedeemCouponResponse> { ): Promise<RedeemCouponResponse> {
if (!this.request.user) { if (!this.request.user) {
throw new HttpException( throw new HttpException(
@ -124,7 +127,7 @@ export class SubscriptionController {
@Post('stripe/checkout-session') @Post('stripe/checkout-session')
@UseGuards(AuthGuard('jwt'), CustomThrottlerGuard, HasPermissionGuard) @UseGuards(AuthGuard('jwt'), CustomThrottlerGuard, HasPermissionGuard)
public async createStripeCheckoutSession( public async createStripeCheckoutSession(
@Body() { couponId, priceId }: { couponId?: string; priceId: string } @Body() { couponId, priceId }: CreateStripeCheckoutSessionDto
): Promise<CreateStripeCheckoutSessionResponse> { ): Promise<CreateStripeCheckoutSessionResponse> {
try { try {
return await this.subscriptionService.createStripeCheckoutSession({ return await this.subscriptionService.createStripeCheckoutSession({

Loading…
Cancel
Save