-
Notifications
You must be signed in to change notification settings - Fork 279
QR Code Login Flow #2767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
QR Code Login Flow #2767
Changes from 15 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
4a42e4d
progress
Velin92 9744e6d
qr code scanning now works, but the API is still unstable
Velin92 aee72b7
code improvements
Velin92 04aa596
code improvements
Velin92 086cb30
improved state handling
Velin92 223cf43
improved the flow
Velin92 529d943
the flow can now reach the login state
Velin92 1ff6cb4
now the code has also a string representation
Velin92 107f1fa
fix onboarding
Velin92 1060bf6
possible fix
Velin92 00345b2
qr code flow
Velin92 3741c62
possible fix
Velin92 9d2f179
fix for the connecting state not working properly
Velin92 638c298
Merge branch 'develop' of https://github.com/vector-im/element-x-ios …
Velin92 64b7934
Discard changes to ElementX.xcodeproj/project.xcworkspace/xcshareddat…
Velin92 45c04c5
updated copies
Velin92 af91e01
better code in the view model
Velin92 94dcff7
accountURL is now async
hughns 5bd9dbb
Refix
hughns 2beb697
Revert "Refix"
Velin92 da7af70
Revert "accountURL is now async"
Velin92 62bc4b8
Merge branch 'develop' of https://github.com/vector-im/element-x-ios …
Velin92 6854682
better error handling for now
Velin92 94b6798
qr code login sdk update for pr building
Velin92 6ea8cde
Merge branch 'develop' into mauroromito/qr_code_api_testing
Velin92 4dd54d8
updated tests
Velin92 525979b
Merge branch 'mauroromito/qr_code_api_testing' of https://github.com/…
Velin92 63efacb
added some view model tests
Velin92 5e652ab
test improvement
Velin92 6adbc02
Merge branch 'develop' of https://github.com/vector-im/element-x-ios …
Velin92 85acde7
updated the branch
Velin92 8bdd4f7
Merge branch 'develop' into mauroromito/qr_code_api_testing
Velin92 d5b5604
updated strings
Velin92 44acd0a
Merge branch 'develop' of https://github.com/vector-im/element-x-ios …
Velin92 16fe49f
Merge branch 'develop' of https://github.com/vector-im/element-x-ios …
Velin92 b44498e
error handling
Velin92 dd9447d
fixing tests
Velin92 6b4d84e
code improvement
Velin92 6b56f17
updated qr code login
Velin92 a3ac12a
Merge branch 'develop' of https://github.com/vector-im/element-x-ios …
Velin92 a60b19a
updated previews and added an error for the
Velin92 26dfc77
Merge branch 'develop' of https://github.com/vector-im/element-x-ios …
Velin92 1e7b74b
updated sdk
Velin92 ce9dc5e
fixed tests
Velin92 b70c072
qr code login enabled is by default false
Velin92 8c49170
added a new error case
Velin92 f7c3bd1
Apply suggestions from code review
Velin92 6af30f3
some pr comments have been addressed
Velin92 58587e8
updated proj
Velin92 e21df9c
moved request camera in app mediator
Velin92 a8b870b
added a test for qr code decoding
Velin92 10c13e0
enable the feature for development builds by default
Velin92 0c099dc
Merge branch 'develop' into mauroromito/qr_code_api_testing
Velin92 0129a1b
qr code login always enabled in nightly
Velin92 848c6ee
removed from developer settings
Velin92 683a534
Merge branch 'mauroromito/qr_code_api_testing' of https://github.com/…
Velin92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
ElementX/Sources/Other/Extensions/AVMetadataMachineReadableCodeObject.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| // | ||
| // Copyright 2024 New Vector Ltd | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| // Helpers to remove ECI headers from QR Code raw data | ||
| // https://gist.github.com/PetrusM/267e2ee8c1d8b5dca17eac085afa7d7c | ||
| import AVKit | ||
| import Foundation | ||
|
|
||
| extension AVMetadataMachineReadableCodeObject { | ||
Velin92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var binaryValue: Data? { | ||
| switch type { | ||
| case .qr: | ||
| guard let binaryValueWithProtocol else { | ||
| return nil | ||
| } | ||
| return removeQrProtocolData(binaryValueWithProtocol) | ||
| case .aztec: | ||
| guard let string = stringValue | ||
| else { return nil } | ||
| return string.data(using: String.Encoding.isoLatin1) | ||
| default: | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| var binaryValueWithProtocol: Data? { | ||
| guard let descriptor else { | ||
| return nil | ||
| } | ||
| switch type { | ||
| case .qr: | ||
| return (descriptor as? CIQRCodeDescriptor)?.errorCorrectedPayload | ||
| case .aztec: | ||
| return (descriptor as? CIAztecCodeDescriptor)?.errorCorrectedPayload | ||
| case .pdf417: | ||
| return (descriptor as? CIPDF417CodeDescriptor)?.errorCorrectedPayload | ||
| case .dataMatrix: | ||
| return (descriptor as? CIDataMatrixCodeDescriptor)?.errorCorrectedPayload | ||
| default: | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| private func removeQrProtocolData(_ input: Data) -> Data? { | ||
| var halves = input.halfBytes() | ||
| var batch = takeBatch(&halves) | ||
| var output = batch | ||
| while !batch.isEmpty { | ||
| batch = takeBatch(&halves) | ||
| output.append(contentsOf: batch) | ||
| } | ||
| return Data(output) | ||
| } | ||
|
|
||
| private func takeBatch(_ input: inout [HalfByte]) -> [UInt8] { | ||
| guard let version = (descriptor as? CIQRCodeDescriptor)?.symbolVersion else { | ||
| return [] | ||
| } | ||
| let characterCountLength = version > 9 ? 16 : 8 | ||
| let mode = input.remove(at: 0) | ||
| var output = [UInt8]() | ||
| switch mode.value { | ||
| // If there is not only binary in the QRCode, then cases should be added here. | ||
| case 0x04: // Binary | ||
| let charactersCount: UInt16 | ||
| if characterCountLength == 8 { | ||
| charactersCount = UInt16(input.takeUInt8()) | ||
| } else { | ||
| charactersCount = UInt16(input.takeUInt16()) | ||
| } | ||
| for _ in 0..<charactersCount { | ||
| output.append(input.takeUInt8()) | ||
| } | ||
| return output | ||
| case 0x00: // End of data | ||
| return [] | ||
| default: | ||
| return [] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private struct HalfByte { | ||
| let value: UInt8 | ||
| } | ||
|
|
||
| private extension [HalfByte] { | ||
| mutating func takeUInt8() -> UInt8 { | ||
| let left = remove(at: 0) | ||
| let right = remove(at: 0) | ||
| return UInt8(left, right) | ||
| } | ||
|
|
||
| mutating func takeUInt16() -> UInt16 { | ||
| let first = remove(at: 0) | ||
| let second = remove(at: 0) | ||
| let third = remove(at: 0) | ||
| let fourth = remove(at: 0) | ||
| return UInt16(first, second, third, fourth) | ||
| } | ||
| } | ||
|
|
||
| private extension Data { | ||
| func halfBytes() -> [HalfByte] { | ||
| var result = [HalfByte]() | ||
| forEach { (byte: UInt8) in | ||
| result.append(contentsOf: byte.halfBytes()) | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| init(_ halves: [HalfByte]) { | ||
| var halves = halves | ||
| var result = [UInt8]() | ||
| while halves.count > 1 { | ||
| result.append(halves.takeUInt8()) | ||
| } | ||
| self.init(result) | ||
| } | ||
| } | ||
|
|
||
| private extension UInt8 { | ||
| func halfBytes() -> [HalfByte] { | ||
| [HalfByte(value: self >> 4), HalfByte(value: self & 0x0F)] | ||
| } | ||
|
|
||
| init(_ left: HalfByte, _ right: HalfByte) { | ||
| self.init((left.value << 4) + (right.value & 0x0F)) | ||
| } | ||
| } | ||
|
|
||
| private extension UInt16 { | ||
| init(_ first: HalfByte, _ second: HalfByte, _ third: HalfByte, _ fourth: HalfByte) { | ||
| let first = UInt16(first.value) << 12 | ||
| let second = UInt16(second.value) << 8 | ||
| let third = UInt16(third.value) << 4 | ||
| let fourth = UInt16(fourth.value) & 0x0F | ||
| let result = first + second + third + fourth | ||
| self.init(result) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.