auth0/Lock.swift

iOS Swift Native Redirection from Mail to the App [Passwordless + Magic link]

aiyub007 opened this issue · 17 comments

I am trying to set the magic link password less using below code

   Lock
                        .passwordless()
                        .withOptions {
                            $0.oidcConformant = true
                            $0.passwordlessMethod = .magicLink
                            

//                            $0.parameters = 
                            

                        }
                        .withConnections {
                            $0.email(name: "email")
                            
                        }
                        .withStyle {
                          $0.title = "Welcome to my App!"
                        }
                        .onAuth {
                          print("Obtained credentials \($0)")
                            
                            
                        }
                        .onError {
                          print("Failed with \($0)")
                        }
                        .onCancel {
                          print("User cancelled")
                        }
                        .onPasswordless {
                            
                          print("Passwordless requested for \($0)")
                            
                        }
                        .present(from: self)`

In result i got email link https://domain.auth0.com/ios/bundle_id/email?code=949921
and when i click in mail it's not redirecting me to the app but it shows code in safari.

I set allowed url on console and url scheme in app as per instruction.

Please provide solution.

Thanks in advance.

Hi @aiyub007,
You need to configure and use Universal Links for the link to open in your app: https://auth0.com/docs/applications/enable-universal-links-support-in-apple-xcode

Hi @Widcket
Thanks for quick reply

I configured everything as displayed there added team ID and AppID[bundle_id] in advance settings

When i run YOUR_DOMAIN/apple-app-site-association in browser to test

it gives me : :

{"applinks":{"apps":[],"details":[{"appID":"TEAMID.bundle_id","paths":["/ios/bundle_id/*"]}]}}

@aiyub007 did you configure Universal Links in Xcode? That is, the Associated Domains entitlement with the applinks:YOUR_AUTH0_DOMAIN.auth0.com value.

Related: #664 (after the app successfully opens from the magic link, the exchange will fail because it is using a legacy grant).

Thanks @Widcket

applinks:YOUR_AUTH0_DOMAIN.auth0.com
This suggestion works

When i come back to the app i doesn't verify me do i have to call the auth.login(code : ) from the link received ?
or it should verify me directly ?

Can you please guide ?

See the linked issue above, we need to update the logic for magic links because it is still using a legacy grant.

@Widcket
That means you are working on it and We need to wait for the next update right?

Waiting for that Thanks for the guidance

Hi @Widcket also have the same issue, hoping this fix is still on track for end of this week, would like to plan out our release cycle.

The PR is up: #667
Please try it out.

@aiyub007 @Jayanth1991 This is out now on v2.22.2.

Hi @Widcket it's the same as before

on tapping Mail it is coming back to the app with url https://server.auth0.com/ios/app_bundle/email?code=212806

It is not coming to

app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]
return Lock.resumeAuth(url, options: options)

nor

application: UIApplication, continue userActivity: NSUserActivity, restorationHandler
return Lock.continueAuth(using: userActivity)

It should work directly auth completion. > Lock.resumeAuth right
or,
Do I have to call the auth.login(code : )
code > recieved from the emaillink ?

If so then there is no changes from the previous version.

Thanks

@aiyub007 is your app using SceneDelegate?

yes

You need to use the relevant methods of SceneDelegate instead of AppDelegate: https://developer.apple.com/documentation/xcode/supporting-universal-links-in-your-app.

@aiyub007 did you configure Universal Links in Xcode? That is, the Associated Domains entitlement with the applinks:YOUR_AUTH0_DOMAIN.auth0.com value.

@Widcket , this was actually more helpful than the documentation page https://auth0.com/docs/get-started/applications/enable-universal-links-support-in-apple-xcode which doesn't mention the entitlement addition. Maybe this page should be updated.