Skip to content

Commit

Permalink
delete magic link implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitSerrano committed May 23, 2024
1 parent ceeb4a2 commit 925528a
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 353 deletions.
1 change: 0 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ AFTER_MEETING_SURVEY_URL=https://startupdetat.typeform.com/to/CQhQfpVU
ENCRYPT_SECRET=un_secret_avec_exactement_64_bit

# Use OIDC auth instead of audioconf's magiclink auth
#FEATURE_OIDC=true
#OIDC_PROVIDER_URL=
#OIDC_CLIENT_ID=
#OIDC_CLIENT_SECRET=
Expand Down
1 change: 0 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ config.FEATURE_JOB_COMPUTE_STATS = process.env.FEATURE_JOB_COMPUTE_STATS === "tr
config.FEATURE_JOB_ANONYMIZE_EMAILS = process.env.FEATURE_JOB_ANONYMIZE_EMAILS === "true" || false
config.FEATURE_JOB_CALLS_STATS = process.env.FEATURE_JOB_CALLS_STATS === "true" || false
config.FEATURE_WEB_ACCESS = process.env.FEATURE_WEB_ACCESS === "true" || false
config.FEATURE_OIDC = process.env.FEATURE_OIDC === "true" || false

config.ANNOUNCEMENTS = process.env.ANNOUNCEMENTS ? process.env.ANNOUNCEMENTS.split("|") : []

Expand Down
7 changes: 2 additions & 5 deletions controllers/createConfController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const config = require("../config")
const db = require("../lib/db")
const emailer = require("../lib/emailer")
const format = require("../lib/format")
const magicLinkAuth = require("../lib/magicLinkAuth")
const oidcAuth = require("../lib/oidcAuth")
const urls = require("../urls")
const { isAcceptedEmail } = require("../lib/emailChecker")
Expand Down Expand Up @@ -45,9 +44,7 @@ const createConfWithDay = async (email, conferenceDay, userTimezoneOffset) => {
}

module.exports.createConf = async (req, res) => {
const confData = await (config.FEATURE_OIDC ?
oidcAuth.finishAuth(req) :
magicLinkAuth.finishAuth(req))
const confData = await oidcAuth.finishAuth(req)

const { email, durationInMinutes, conferenceDay, userTimezoneOffset } = confData

Expand Down Expand Up @@ -146,4 +143,4 @@ module.exports.cancelConf = async (req, res) => {

function shouldSendWebAccessMail(email) {
return isAcceptedEmail(email, config.EMAIL_WEB_ACCESS_WHITELIST) && config.FEATURE_WEB_ACCESS
}
}
10 changes: 1 addition & 9 deletions controllers/startAuthController.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
const config = require("../config.js")
const magicLinkAuth = require("../lib/magicLinkAuth")
const oidcAuth = require("../lib/oidcAuth")


module.exports.startAuth = async (req, res) => {
const userTimezoneOffset = req.body.userTimezoneOffset
const email = req.body.email
const conferenceDurationInMinutes = req.body.durationInMinutes
const conferenceDayString = req.body.day
if (typeof conferenceDayString === 'undefined' && typeof conferenceDurationInMinutes === 'undefined') {
throw new Error('Both conferenceDayString and conferenceDurationInMinutes are undefined. This should not happen.')
}

const authRequest = await (
config.FEATURE_OIDC ?
oidcAuth.startAuth(email, conferenceDurationInMinutes, conferenceDayString, userTimezoneOffset) :
magicLinkAuth.startAuth(email, conferenceDurationInMinutes, conferenceDayString, userTimezoneOffset)
)
const authRequest = await oidcAuth.startAuth(conferenceDurationInMinutes, conferenceDayString, userTimezoneOffset)

if (authRequest.error) {
console.log("Error in authentication", authRequest.error)
Expand Down
84 changes: 0 additions & 84 deletions lib/magicLinkAuth.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/oidcAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports.getClient = async () => {
return client
}

module.exports.startAuth = async (email, conferenceDurationInMinutes, conferenceDayString, userTimezoneOffset) => {
module.exports.startAuth = async (conferenceDurationInMinutes, conferenceDayString, userTimezoneOffset) => {
const client = await this.getClient()

/* todo : store the code_verifier in DB. We don't use it for now.
Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports.startAuth = async (email, conferenceDurationInMinutes, conference
// todo write test : null nonce fails
try {
await db.insertOidcRequest(state, nonce, conferenceDurationInMinutes, conferenceDayString, userTimezoneOffset)
console.log(`OIDC request créé pour ${format.hashForLogs(email)}`)
console.log(`OIDC request créé pour state ${state}`)
} catch(err) {
console.log("Error when inserting authrequest token in DB", err)
return { error: "Une erreur interne s'est produite, nous n'avons pas pu créer votre conférence." }
Expand Down
36 changes: 0 additions & 36 deletions test/createConfControllerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const app = require("../index")
const conferences = require("../lib/conferences")
const db = require("../lib/db")
const emailer = require("../lib/emailer")
const magicLinkAuth = require("../lib/magicLinkAuth")
const oidcAuth = require("../lib/oidcAuth")
const urls = require("../urls")
const { encrypt } = require("../lib/crypto")
Expand All @@ -20,11 +19,9 @@ describe("createConfController", function() {
let insertConfStub
let sendWebAccessEmailStub

let oidcFlagBackupValue
let webAccessFlagBackupValue

beforeEach(function(done) {
oidcFlagBackupValue = config.FEATURE_OIDC
webAccessFlagBackupValue = config.FEATURE_WEB_ACCESS
config.FEATURE_WEB_ACCESS = true

Expand All @@ -37,7 +34,6 @@ describe("createConfController", function() {
})

afterEach(function(done) {
config.FEATURE_OIDC = oidcFlagBackupValue
config.FEATURE_WEB_ACCESS = webAccessFlagBackupValue

createConfStub.restore()
Expand All @@ -47,42 +43,10 @@ describe("createConfController", function() {
done()
})

describe("using magicLinkAuth", () => {
let magicLinkFinishAuthStub

beforeEach(function() {
config.FEATURE_OIDC = false
magicLinkFinishAuthStub = sinon.stub(magicLinkAuth, "finishAuth")
})

afterEach(function() {
magicLinkFinishAuthStub.restore()
})

it("should create conf and send email", function(done) {
shouldCreateConfAndSendEmail(done, magicLinkFinishAuthStub)
})

it("should redirect when finishAuth has failed", function(done) {
shouldRedirectWhenFinishAuthHasFailed(done, magicLinkFinishAuthStub)
})

it("should redirect when conf was not created", function(done) {
shouldRedirectWhenConfWasNotCreated(done, magicLinkFinishAuthStub)
})

it("should redirect when email was not sent", function(done) {
shouldRedirectWhenEmailWasNotSent(done, magicLinkFinishAuthStub)
})

})


describe("using OIDC auth", () => {
let oidcFinishAuthStub

beforeEach(function() {
config.FEATURE_OIDC = true
oidcFinishAuthStub = sinon.stub(oidcAuth, "finishAuth")
})

Expand Down
139 changes: 0 additions & 139 deletions test/magicLinkAuthTest.js

This file was deleted.

Loading

0 comments on commit 925528a

Please sign in to comment.