@@ -179,18 +179,21 @@ class AuthenticationService: AuthenticationServiceProtocol {
179179 return progressSubject. asCurrentValuePublisher ( )
180180 }
181181
182- // At some stage the SDK will have a `qrCodeData.intent` which we should check before continuing here.
183- // Note the equivalent check will also happen for linking a device by QR in the LinkNewDeviceService.
182+ // n.b. We rely on the SDK checking that the intent of the QR is suitable for us to login with.
184183
185- guard let scannedServerName = qrData. serverName ( ) else {
184+ // Future versions of the QR should always give us the baseUrl
185+ guard let scannedServerNameOrBaseUrl = qrData. baseUrl ( ) ?? qrData. serverName ( ) else {
186+ // With the older version of QR we treat the presence of serverName as meaning that the other device
187+ // is not signed in.
186188 MXLog . error ( " The QR code is from a device that is not yet signed in. " )
187189 progressSubject. send ( completion: . failure( . qrCodeError( . deviceNotSignedIn) ) )
188190 return progressSubject. asCurrentValuePublisher ( )
189191 }
190192
191- if !appSettings. allowOtherAccountProviders, !appSettings. accountProviders. contains ( scannedServerName) {
192- MXLog . error ( " The scanned device's server is not allowed: \( scannedServerName) " )
193- progressSubject. send ( completion: . failure( . qrCodeError( . providerNotAllowed( scannedProvider: scannedServerName, allowedProviders: appSettings. accountProviders) ) ) )
193+ // TODO: do we need to extract the serverName from the baseUrl?
194+ if !appSettings. allowOtherAccountProviders, !appSettings. accountProviders. contains ( scannedServerNameOrBaseUrl) {
195+ MXLog . error ( " The scanned device's server is not allowed: \( scannedServerNameOrBaseUrl) " )
196+ progressSubject. send ( completion: . failure( . qrCodeError( . providerNotAllowed( scannedProvider: scannedServerNameOrBaseUrl, allowedProviders: appSettings. accountProviders) ) ) )
194197 return progressSubject. asCurrentValuePublisher ( )
195198 }
196199
@@ -201,7 +204,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
201204
202205 Task {
203206 do {
204- let client = try await makeClient ( homeserverAddress: scannedServerName )
207+ let client = try await makeClient ( homeserverAddress: scannedServerNameOrBaseUrl )
205208 let qrCodeHandler = client. newLoginWithQrCodeHandler ( oidcConfiguration: appSettings. oidcConfiguration. rustValue)
206209 try await qrCodeHandler. scan ( qrCodeData: qrData, progressListener: listener)
207210
@@ -281,6 +284,8 @@ private extension HumanQrLoginError {
281284 . qrCodeError( . slidingSyncNotAvailable)
282285 case . OtherDeviceNotSignedIn:
283286 . qrCodeError( . deviceNotSignedIn)
287+ case . UnsupportedQrCodeType:
288+ . qrCodeError( . invalidQRCode)
284289 case . Unknown, . OidcMetadataInvalid, . CheckCodeAlreadySent, . CheckCodeCannotBeSent:
285290 . qrCodeError( . unknown)
286291 }
0 commit comments