Skip to content

Commit b5790dd

Browse files
committed
Documentation
1 parent 6dec2b6 commit b5790dd

File tree

8 files changed

+162
-70
lines changed

8 files changed

+162
-70
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This library allows you to authenticate with Uber services and interact with th
44

55
## Requirements
66

7-
- iOS 13.0+
7+
- iOS 14.0+
88
- Xcode 14.0+
99
- Swift 5.0+
1010

@@ -50,7 +50,7 @@ Add the following code snippet, replacing the placeholders within the square bra
5050
<string>ubereats</string>
5151
<string>uberdriver</string>
5252
</array>
53-
<key>UberAuth</key>
53+
<key>Uber</key>
5454
<dict>
5555
<key>ClientID</key>
5656
<string>[Client ID]</string>

Sources/UberAuth/Button/LoginButton.swift

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public final class LoginButton: UberButton {
149149
}
150150

151151
private func logout() {
152-
// TODO: Implement UberAuth.logout()
153152
tokenManager.deleteToken(identifier: Constants.tokenIdentifier)
154153
update()
155154
}

Sources/UberAuth/README.md

+103-46
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
2. [Setup](#setup)
44
1. [SDK Configuration](#sdk-configuration)
55
3. [Authenticating](#authenticating)
6-
1. [Login](#login)
7-
2. [Login Context](#login-context)
8-
3. [Auth Destination](#auth-destination)
6+
1. [Simple Login](#simple-login)
7+
2. [Customized Login](#customized-login)
8+
3. [Auth Destinations](#auth-destinations)
99
4. [Auth Providers](#auth-providers)
10-
1. [AuthorizationCodeAuthProvider](#wip-authorizationcoreauthprovider)
11-
5. [Prefilling User Information](#wip-prefilling-user-information)
12-
6. [Responding to Redirects](#wip-responding-to-redirects)
13-
1. [Using UIKit](#using-uikit)
14-
2. [Using SwiftUI](#using-swiftui)
15-
7. [Exchanging Authorization Code](#exchanging-authorization-code)
10+
* [AuthorizationCodeAuthProvider](#authorizationcoreauthprovider)
11+
5. [Responding to Redirects](#responding-to-redirects)
12+
* [Using UIKit](#using-uikit)
13+
* [Using SwiftUI](#using-swiftui)
14+
6. [Exchanging Authorization Code](#exchanging-authorization-code)
15+
7. [Prefilling User Information](#prefilling-user-information)
1616
8. [Login Button](#login-button)
1717

1818
# Prerequisites
@@ -48,7 +48,7 @@ Once registered in the developer portal, add your redirect URI to your Xcode pro
4848
</array>
4949
</dict>
5050
</array>
51-
<key>UberAuth</key>
51+
<key>Uber</key>
5252
<dict>
5353

5454
...
@@ -61,16 +61,16 @@ Once registered in the developer portal, add your redirect URI to your Xcode pro
6161

6262
# Authenticating
6363

64-
## Login
64+
## Simple Login
6565
To authenticate your app's user with Uber's backend, use the UberAuth API. In the simplest case, call the login method and respond to the result.
6666

6767
```swift
68-
UberAuth.login { result in
68+
UberAuth.login { result: Result<Client, UberAuthError> in
6969
// Handle result
7070
}
7171
```
7272

73-
Upon success, the result of the callback will contain a Client object containing all credentials necessary to authenticate your user.
73+
Upon success, the result of the callback will contain a `Client` object containing all credentials necessary to authenticate your user.
7474

7575
| Property | Type | Description |
7676
| ------------- | ------------- | ------------- |
@@ -86,7 +86,7 @@ Upon success, the result of the callback will contain a Client object containing
8686
Upon failure, the result will contain an error of type UberAuthError. See [Errors](./Errors/README.md) for more information.
8787

8888

89-
## Login Context
89+
## Customized Login
9090

9191
For more complicated use cases, an auth context may be supplied to the login function. Use this type to specify additional customizations for the login experience:
9292

@@ -110,7 +110,7 @@ UberAuth.login(
110110
```
111111

112112

113-
## Auth Destination
113+
## Auth Destinations
114114

115115
There are two locations or `AuthDestination`s where authentication can be handled.
116116

@@ -140,37 +140,9 @@ UberAuth.login(
140140

141141
An Auth Provider supplies logic for a specific authentication grant flow. Currently, the only supported auth provider is `AuthorizationCoreAuthProvider`.
142142

143-
### [WIP] AuthorizationCoreAuthProvider
143+
### AuthorizationCoreAuthProvider
144144

145-
An Auth Provider that supplies performs the Authorization Code Grant Flow as specified in the [OAuth 2.0 Framework](https://datatracker.ietf.org/doc/html/rfc6749#section-4.1).
146-
147-
148-
## [WIP] Prefilling User Information
149-
If you would like text fields during signup to be pre-populated with user information you can do so using the prefill API. Partial information is accepted.
150-
There are two ways to provide this information:
151-
152-
**Using the LoginButton / DataSource**
153-
154-
WIP
155-
156-
**Using LoginManager Directly**
157-
```
158-
let loginManager = LoginManager(loginType: .authorizationCode)
159-
160-
let prefill = Prefill(
161-
162-
phoneNumber: "12345678900",
163-
firstName: "Jane",
164-
lastName: "Doe"
165-
)
166-
167-
loginManager.login(
168-
scopes: [.profile],
169-
presentingViewController: viewController,
170-
prefillValues: prefill,
171-
completion: nil
172-
)
173-
```
145+
AuthorizationCoreAuthProvider performs the Authorization Code Grant Flow as specified in the [OAuth 2.0 Framework](https://datatracker.ietf.org/doc/html/rfc6749#section-4.1). AuthorizationCoreAuthProvider is currently the only supported auth provider.
174146

175147

176148
## Responding to Redirects
@@ -257,6 +229,91 @@ Upon successful authentication, the Client object returned will contain a valid
257229

258230
**Note:** Authorization Code **will be nil** as it has been used for the token exchange and is no longer valid.
259231

232+
## Prefilling User Information
233+
The SDK supports the OpenID `login_hint` parameter for prefilling user information when authenticating with Uber.
234+
To pass user information into the login page, ise the Prefill API when constructing the AuthContext. Partial information is accepted.
235+
236+
**Note:** Prefill information is only supported using the `.inApp` login type.
237+
238+
**Using UberAuth**
239+
```
240+
let prefill = Prefill(
241+
242+
phoneNumber: "5555555555",
243+
firstName: "Jane",
244+
lastName: "Doe"
245+
)
246+
247+
UberAuth.login(
248+
context: AuthContext(
249+
authDestination: .inApp,
250+
authProvider: .authorizationCode(),
251+
prefill: prefill
252+
),
253+
completion: { _ in }
254+
)
255+
```
256+
257+
**Using the LoginButton / DataSource**
258+
259+
```
260+
final class MyLoginButtonDataSource: LoginButtonDataSource {
261+
262+
func authContext(_ button: LoginButton) -> AuthContext {
263+
let prefill = Prefill(
264+
265+
phoneNumber: "5555555555",
266+
firstName: "Jane",
267+
lastName: "Doe"
268+
)
269+
270+
return AuthContext(
271+
authDestination: .inApp,
272+
authProvider: .authorizationCode(),
273+
prefill: prefill
274+
)
275+
}
276+
}
277+
```
278+
260279

261280
### Login Button
262-
Coming Soon
281+
282+
As a convenience, the SDK provides a `LoginButton` class that can be used to log a user in or out.
283+
284+
<img src="../../img/login_button.png?raw=true" width=600 alt="Login Button"/>
285+
286+
For simple cases, construct the button using the default initializer.
287+
```
288+
import UberAuth
289+
290+
let loginButton = LoginButton()
291+
```
292+
293+
294+
To receive the login result, conform to the `LoginButtonDelegate`.
295+
296+
```
297+
298+
loginButton.delegate = MyLoginButtonDelegate()
299+
300+
...
301+
302+
final class MyLoginButtonDelegate: LoginButtonDelegate {
303+
304+
func loginButton(_ button: LoginButton, didLogoutWithSuccess success: Bool) {
305+
// Successful logout
306+
}
307+
308+
func loginButton(_ button: LoginButton, didCompleteLoginWithResult result: Result<Client, UberAuthError>) {
309+
switch result {
310+
case .success(let client):
311+
// Handle Client response
312+
break
313+
case .failure(let error):
314+
// Handle UberAuthError
315+
break
316+
}
317+
}
318+
}
319+
```

examples/README.md

+3-21
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,9 @@
22

33
## Universal Link Sample App
44

5-
An example of how to authenticate with Uber services using an [auth code grant flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow).
5+
See the [Universal Link Example Readme](./UniversalLinkExample/README.md)
66

7-
This sample app will demonstrate how to:
8-
1. Build a universal link that will launch the native Uber app if installed
9-
2. Make a /authorize request to Uber's backend and handle the auth code in the response url
10-
3. Exchange the auth code for a valid access token that can be used to make authenticated requests to Uber's backend services
117

12-
### Setup
13-
1. Add the sample app's redirect URI to your app's configuration in the [Uber Developer Portal](https://developer.uber.com/)
8+
## UberSDK Sample App
149

15-
`universallinkexample://app`
16-
17-
2. Enter your app's ClientID found in the in the sample app's Info.plist. This can also be done inside the sample app.
18-
3. [Optional] Install the native Uber app on your device
19-
20-
21-
22-
## SDK Sample Apps
23-
24-
Requires Xcode 9
25-
26-
There are two sample apps, one written in Objective-C, and another written in Swift.
27-
28-
[TODO: Installation instructions]
10+
See the [Universal Link Example Readme](./UberSDK/README.md)

examples/UberSDK/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# UberSDK
2+
3+
A sample app demonstrating how to use the Uber iOS SDK.
4+
5+
<img src="../../img/uber_sdk.png?raw=true" width=300 alt="Login Button"/>
6+
7+
## Setup
8+
In the UberSDK project's Info.plist, replace the ClientID and RedirectURI with your app's values in the [Uber Developer's Portal](https://developer.uber.com/dashboard/).
9+
10+
## Login
11+
Example usage for the UberAuth login class.
12+
13+
### Auth Type
14+
Specifies the auth grant flow to use for login. Authorization Code is the only option.
15+
16+
### Destination
17+
Sets the auth destination for login. `.inApp` and `.native` are the only options.
18+
If the native Uber app is not installed on the device, `.inApp` is used.
19+
20+
### Exchange Auth Code for Token
21+
Determines if the authorization code should be exchanged locally for an access token
22+
23+
### Always ask for Login
24+
If enabled, the Uber login page will always ask for re-authentication.
25+
26+
### Always ask for Consent
27+
If enabled, the user will always have to agree to linking their account.
28+
29+
### Prefill Values
30+
Allows setting optional values for prefilling user information on the login screen.
31+
32+
33+
## Uber Button
34+
Example usage of the LoginButton convenience UI for login / logout.
35+
36+
## Request a Ride Button
37+
Example usage of the RideRequestButton convenience UI for requesting a ride.
38+
To enable, first log in using either the Login or UberButton section.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Universal Link Example
2+
3+
An example of how to authenticate with Uber services using an [auth code grant flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow).
4+
5+
This sample app will demonstrate how to:
6+
1. Build a universal link that will launch the native Uber app if installed
7+
2. Make a /authorize request to Uber's backend and handle the auth code in the response url
8+
3. Exchange the auth code for a valid access token that can be used to make authenticated requests to Uber's backend services
9+
10+
### Setup
11+
1. Add the sample app's redirect URI to your app's configuration in the [Uber Developer Portal](https://developer.uber.com/)
12+
13+
`universallinkexample://app`
14+
15+
2. Enter your app's ClientID found in the in the sample app's Info.plist. This can also be done inside the sample app.
16+
3. [Optional] Install the native Uber app on your device

img/login_button.png

27.8 KB
Loading

img/uber_sdk.png

198 KB
Loading

0 commit comments

Comments
 (0)