Skip to content

Commit

Permalink
Backport enrollment override fix from OV codebase (#166)
Browse files Browse the repository at this point in the history
- Remove enrollment data as well when duplicate enrollment is detected
- Search duplicate by enrollmentId instead of orgI+userId combo
  • Loading branch information
IldarAbdullin-okta authored Oct 27, 2023
1 parent 8f9d961 commit 902696e
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class OktaSharedSQLite: OktaSharedSQLiteProtocol {
try db.execute(
sql: "DELETE from EnrolledMethod WHERE enrollmentId = ? AND orgId = ?",
arguments: [enrollmentDuplicate.enrollmentId, enrollmentDuplicate.organization.id])
try db.execute(
sql: "DELETE from Enrollment WHERE enrollmentId = ?",
arguments: [enrollmentDuplicate.enrollmentId])
}
try db.execute(sql: "INSERT INTO Enrollment (enrollmentId, orgId, serverErrorCode, orgUrl, userId, username, deviceId, createdTimestamp, updatedTimestamp) VALUES (:enrollmentId, :orgId, :serverErrorCode, :orgUrl, :userId, :username, :deviceId, :createdTimestamp, :updatedTimestamp) ON CONFLICT(enrollmentId,orgId) DO UPDATE SET enrollmentId = :enrollmentId, orgId = :orgId, serverErrorCode = :serverErrorCode, orgUrl = :orgUrl, userId = :userId, username = :username, deviceId = :deviceId, updatedTimestamp = :updatedTimestamp", arguments: writeArguments)

Expand Down Expand Up @@ -158,7 +161,7 @@ class OktaSharedSQLite: OktaSharedSQLiteProtocol {

func storeEnrollment(_ enrollment: AuthenticatorEnrollmentProtocol) throws {
let writeArguments = try enrollmentStatementWriteArguments(enrollment)
let enrollmentDuplicate = enrollmentByOrgId(enrollment.organization.id, userId: enrollment.user.id)
let enrollmentDuplicate = enrollmentById(enrollmentId: enrollment.enrollmentId)
do {
try pool?.write({ db in
try storeEnrollment(enrollment, oldEnrollment: enrollmentDuplicate, writeArguments: writeArguments, db: db)
Expand Down

0 comments on commit 902696e

Please sign in to comment.