@@ -294,6 +294,9 @@ extension AppDelegate: FTROpenURLDelegate {
294294 case . authentication:
295295 authenticate ( url: url, options: options)
296296 return true
297+ case . usernamelessAuth:
298+ usernamelessAuthenticate ( url: url)
299+ return true
297300 default :
298301 break
299302 }
@@ -306,24 +309,24 @@ extension AppDelegate: FTROpenURLDelegate {
306309 continue userActivity: NSUserActivity ,
307310 restorationHandler: @escaping ( [ UIUserActivityRestoring ] ? ) -> Void
308311 ) -> Bool {
312+ print ( " Received Universal Link: \( userActivity. webpageURL) " )
313+
309314 // Check if the activity type is a Universal Link
310315 guard userActivity. activityType == NSUserActivityTypeBrowsingWeb,
311316 let url = userActivity. webpageURL else { return false }
312-
313- print ( " Received Universal Link: \( url) " )
314317
315318 // Handle the universal link URL here
316319 switch FTRUtils . typeFromURL ( url) {
317320 case . activation:
318- print ( " ernoll " )
319321 enroll ( url: url)
320322 return true
321323 case . authentication:
322- print ( " authentication " )
323324 authenticate ( url: url)
324325 return true
326+ case . usernamelessAuth:
327+ usernamelessAuthenticate ( url: url)
328+ return true
325329 default :
326- print ( " default " )
327330 break
328331 }
329332
@@ -395,6 +398,69 @@ extension AppDelegate: FTROpenURLDelegate {
395398 }
396399 }
397400
401+ private func usernamelessAuthenticate( url: URL ) {
402+ guard let data = FTRUtils . usernamelessAuthDataFromURL ( url) ,
403+ let userId = try ? FTRClient . shared. getAccounts ( ) . first? . userId,
404+ let vc = window? . rootViewController else { return }
405+
406+ guard FTRUtils . typeFromURL ( url) == . usernamelessAuth,
407+ let usernamelessData = FTRUtils . usernamelessAuthDataFromURL ( url)
408+ else { return }
409+
410+ FTRClient . shared. sessionInfo ( . with( token: data. sessionToken, userId: userId) ) { session in
411+ let extras = session. extraInfo ?? [ ]
412+ let mutableFormattedExtraInfo = extras. reduce ( " " ) { result, extraInfo in
413+ result + " \( extraInfo. key) : \( extraInfo. value) \n "
414+ }
415+
416+ let title = " Approve "
417+ let message = " Request Information \n \( mutableFormattedExtraInfo) "
418+ let alert = UIAlertController ( title: title, message: message, preferredStyle: . alert)
419+ alert. addAction ( UIAlertAction ( title: " Deny " , style: . destructive, handler: nil ) )
420+ alert. addAction ( UIAlertAction ( title: " Approve " , style: . default, handler: { _ in
421+ do {
422+ let accounts = try FTRClient . shared. getAccounts ( )
423+ let ac = UIAlertController ( title: " Usernameless Auth " , message: " Select an account " , preferredStyle: . actionSheet)
424+
425+ for account in accounts {
426+ ac. addAction ( UIAlertAction ( title: account. username ?? " Username N/A " , style: . default, handler: { _ in
427+ FTRClient . shared. replyAuth ( AuthReplyParameters . approveUsernamelessAuth ( data. sessionToken, userId: account. userId, extraInfo: extras) , success: {
428+ vc. dismiss ( animated: true ) {
429+ vc. showAlert ( title: " Success " , message: " User authenticated successfully! " ) { _ in
430+ if let redirect = data. mobileAuthRedirectUri {
431+ self . authenticationURLFinished ( redirect)
432+ }
433+ }
434+ }
435+ } , failure: { error in
436+ vc. dismiss ( animated: true ) {
437+ vc. showAlert ( title: " Error " , message: error. localizedDescription) { _ in
438+ if let redirect = data. mobileAuthRedirectUri {
439+ self . authenticationURLFinished ( redirect)
440+ }
441+ }
442+ }
443+ } )
444+ } ) )
445+ }
446+
447+ ac. addAction ( UIAlertAction ( title: " Cancel " , style: . cancel, handler: nil ) )
448+
449+ vc. dismiss ( animated: true ) {
450+ vc. present ( ac, animated: true , completion: nil )
451+ }
452+ } catch {
453+ vc. showAlert ( title: " Error " , message: error. localizedDescription)
454+ }
455+ } ) )
456+ vc. present ( alert, animated: true , completion: nil )
457+ } failure: { error in
458+ vc. dismiss ( animated: true ) {
459+ self . showAlert ( title: " Error " , message: error. localizedDescription)
460+ }
461+ }
462+ }
463+
398464 private func authenticate(
399465 url authenticationUrl: URL ,
400466 options: [ UIApplication . OpenURLOptionsKey : Any ] = [ : ]
0 commit comments