uber / rides-ios-sdk

Uber Rides iOS SDK (beta)
https://developer.uber.com/docs
MIT License
371 stars 123 forks source link

Authentication through Uber native apps #293

Closed mohssenfathi closed 5 months ago

mohssenfathi commented 5 months ago

Description

This PR implements two major features:

Native authentication

Depending on the supplied configuration, the implementer may want auth to occur from inside the Uber app, as opposed to internal to the SDK in an embedded web browser.

Pulling from the code comments:

There are three possible destinations for auth through this method:
    1. The native Uber app
    2. The OS supplied Safari browser
    3. In app auth through ASWebAuthenticationSession

 This method will run through the desired native app destinations supplied in `appPriority`.
 For each one it will:
    * Use the configuration provider to determine if the app is installed, using UIApplication's openUrl. If the app's scheme has not been registered in the Info.plist and is not queryable it will default to true and continue with the auth flow. If it is registered but not installed, we will continue to the next app.
    * Build a universal link specific to the current app destination
    * Attempt to launch the app using the `applicationLauncher`. If the app is installed, the native app should be launched (1), if not the OS supplied browser will be launched (2)

If all app destinations have been exhausted and no url has been launched we fall back to in app auth (3)

Redirect URI handling

After authenticating in the native app, the success/failure response will be sent back to the calling app via deeplink. This then needs to be forwarded to the lib via the UberAuth.handle() method. Logic is fairly simple here, we parse the response url using AuthorizationCodeResponseParser and call the store completion with the result.

Testing

Manually

Prerequisite: Have at least one of Uber, UberEats, or UberDriver installed

Unit tests

Unit tests added for all logic heavy classes

Video

https://github.com/uber/rides-ios-sdk/assets/5241321/1ad8642b-7fb6-45d7-9180-34716ee22e43