Skip to content

Commit bd87506

Browse files
Merge pull request #20352 from mozilla/PAY-3612
feat(payments-next): add OAuth strategy guard
2 parents 11a364e + 9738a45 commit bd87506

25 files changed

Lines changed: 643 additions & 0 deletions

apps/payments/api/.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ GLEAN_CONFIG__LOGGER_APP_NAME='fxa-payments-next'
6262
FXA_WEBHOOK_CONFIG__FXA_WEBHOOK_ISSUER=https://accounts.firefox.com/
6363
FXA_WEBHOOK_CONFIG__FXA_WEBHOOK_JWKS_URI=https://oauth.accounts.firefox.com/v1/jwks/
6464
FXA_WEBHOOK_CONFIG__FXA_WEBHOOK_AUDIENCE=
65+
66+
# FXA OAuth Config
67+
FXA_O_AUTH_CONFIG__FXA_O_AUTH_JWKS_URI=http://localhost:9000/v1/jwks
68+
FXA_O_AUTH_CONFIG__FXA_O_AUTH_ISSUER=http://localhost:3030
69+
FXA_O_AUTH_CONFIG__FXA_O_AUTH_REQUIRED_SCOPE=https://identity.mozilla.com/account/subscriptions
70+
FXA_O_AUTH_CONFIG__FXA_O_AUTH_SERVER_URL=http://localhost:9000

apps/payments/api/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TypedConfigModule, dotenvLoader } from 'nest-typed-config';
33
import { AppController } from './app.controller';
44
import { AppService } from './app.service';
55
import { RootConfig } from '../config';
6+
import { AuthModule } from '@fxa/payments/auth';
67
import {
78
CmsWebhooksController,
89
CmsWebhookService,
@@ -46,6 +47,7 @@ import { NimbusClient, NimbusClientConfig } from '@fxa/shared/experiments';
4647

4748
@Module({
4849
imports: [
50+
AuthModule,
4951
TypedConfigModule.forRoot({
5052
schema: RootConfig,
5153
load: dotenvLoader({

apps/payments/api/src/config/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MySQLConfig } from '@fxa/shared/db/mysql/core';
1010
import { FxaWebhookConfig, StripeEventConfig } from '@fxa/payments/webhooks';
1111
import { StatsDConfig } from '@fxa/shared/metrics/statsd';
1212
import { FirestoreConfig } from 'libs/shared/db/firestore/src/lib/firestore.config';
13+
import { FxaOAuthConfig } from '@fxa/payments/auth';
1314

1415
export class RootConfig {
1516
@Type(() => MySQLConfig)
@@ -61,4 +62,9 @@ export class RootConfig {
6162
@ValidateNested()
6263
@IsDefined()
6364
public readonly fxaWebhookConfig!: Partial<FxaWebhookConfig>;
65+
66+
@Type(() => FxaOAuthConfig)
67+
@ValidateNested()
68+
@IsDefined()
69+
public readonly fxaOAuthConfig!: Partial<FxaOAuthConfig>;
6470
}

libs/payments/auth/.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}

libs/payments/auth/jest.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
displayName: 'payments-auth',
3+
preset: '../../../jest.preset.js',
4+
testEnvironment: 'node',
5+
transform: {
6+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
7+
},
8+
moduleFileExtensions: ['ts', 'js', 'html'],
9+
coverageDirectory: '../../../coverage/libs/payments/auth',
10+
};

libs/payments/auth/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@fxa/payments/auth",
3+
"version": "0.0.1"
4+
}

libs/payments/auth/project.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "payments-auth",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/payments/auth/src",
5+
"projectType": "library",
6+
"tags": [],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/esbuild:esbuild",
10+
"outputs": ["{options.outputPath}"],
11+
"options": {
12+
"outputPath": "dist/libs/payments/auth",
13+
"main": "libs/payments/auth/src/index.ts",
14+
"tsConfig": "libs/payments/auth/tsconfig.lib.json",
15+
"assets": ["libs/payments/auth/*.md"],
16+
"format": ["cjs"]
17+
}
18+
},
19+
"test-unit": {
20+
"executor": "@nx/jest:jest",
21+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
22+
"options": {
23+
"jestConfig": "libs/payments/auth/jest.config.ts"
24+
}
25+
}
26+
}
27+
}

libs/payments/auth/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
export * from './lib/auth.module';
6+
export * from './lib/fxa-oauth-auth.guard';
7+
export * from './lib/fxa-access-token.schemas';
8+
export * from './lib/fxa-oauth.config';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
import { Module } from '@nestjs/common';
6+
7+
import { FxaOAuthJwtStrategy } from './fxa-oauth-jwt.strategy';
8+
import { FxaOAuthVerifyStrategy } from './fxa-oauth-verify.strategy';
9+
10+
@Module({
11+
providers: [FxaOAuthJwtStrategy, FxaOAuthVerifyStrategy],
12+
exports: [FxaOAuthJwtStrategy, FxaOAuthVerifyStrategy],
13+
})
14+
export class AuthModule {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
import { faker } from '@faker-js/faker';
6+
import { FxaAccessTokenClaims } from '../fxa-access-token.schemas';
7+
8+
export const FxaAccessTokenClaimsFactory = (
9+
override?: Partial<FxaAccessTokenClaims>
10+
): FxaAccessTokenClaims => ({
11+
sub: faker.string.hexadecimal({ length: 32, prefix: '' }),
12+
client_id: faker.string.hexadecimal({ length: 16, prefix: '' }),
13+
scope: 'profile',
14+
...override,
15+
});

0 commit comments

Comments
 (0)