Skip to content

Commit

Permalink
auth refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewplummer committed Feb 5, 2025
1 parent 37f9390 commit 47d3916
Show file tree
Hide file tree
Showing 130 changed files with 3,490 additions and 3,519 deletions.
3 changes: 3 additions & 0 deletions services/api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ TWILIO_WEBHOOK_URL=
TWILIO_AUTH_TOKEN=AC21717619d8cf45502cc2f7cd7aee139d

# Sign in with Google
# https://developers.google.com/identity/sign-in/web/sign-in
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

# Sign in with Apple
# https://developer.apple.com/help/account/configure-app-capabilities/about-sign-in-with-apple/
APPLE_SERVICE_ID=

# OpenAI
Expand Down
16 changes: 5 additions & 11 deletions services/api/__mocks__/@simplewebauthn/server.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
function generateAuthenticationOptions() {
function generateAuthenticationOptions(options) {
return {
rpId: 'rpID',
challenge: 'challenge',
allowCredentials: [
{
id: 'id',
type: 'public-key',
transports: ['hybrid', 'internal'],
},
],
...options,
rpID: 'rpID',
timeout: 60000,
challenge: 'challenge',
userVerification: 'preferred',
};
}
Expand Down Expand Up @@ -85,7 +79,7 @@ function verifyRegistrationResponse(options) {
},
};
} else {
throw new Error('Bad register response.');
throw new Error('Bad registration response.');
}
}

Expand Down
11 changes: 9 additions & 2 deletions services/api/__mocks__/google-auth-library.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
class MockClient {
getToken(code) {
return {
tokens: {
id_token: code,
},
};
}
verifyIdToken(options) {
const { idToken } = options;

Expand All @@ -16,7 +23,7 @@ class MockClient {
}
}

function createToken(payload) {
function createCode(payload) {
payload.givenName ||= 'First Name';
payload.familyName ||= 'Last Name';
payload.email_verified ??= true;
Expand All @@ -25,5 +32,5 @@ function createToken(payload) {

module.exports = {
OAuth2Client: MockClient,
createToken,
createCode,
};
7 changes: 6 additions & 1 deletion services/api/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ process.env.ENV_NAME = 'test';
process.env.LOG_LEVEL ||= 'warn';
module.exports = {
preset: '@shelf/jest-mongodb',
setupFilesAfterEnv: ['<rootDir>/src/utils/testing/setup/autoclean', '<rootDir>/src/utils/testing/setup/database'],
setupFilesAfterEnv: [
'<rootDir>/src/utils/testing/setup/autoclean',
'<rootDir>/src/utils/testing/setup/database',
'<rootDir>/src/utils/testing/setup/matchers',
],
// Only run on changed files without extra arguments.
watchPlugins: ['./src/utils/testing/ChangedFilesPlugin'],
// https://github.com/shelfio/jest-mongodb#6-jest-watch-mode-gotcha
watchPathIgnorePatterns: ['globalConfig'],
maxWorkers: '50%',
};
Loading

0 comments on commit 47d3916

Please sign in to comment.