Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #318

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This library allows you to authenticate with Uber services and interact with th

## Requirements

- iOS 13.0+
- iOS 14.0+
- Xcode 14.0+
- Swift 5.0+

Expand Down Expand Up @@ -50,7 +50,7 @@ Add the following code snippet, replacing the placeholders within the square bra
<string>ubereats</string>
<string>uberdriver</string>
</array>
<key>UberAuth</key>
<key>Uber</key>
<dict>
<key>ClientID</key>
<string>[Client ID]</string>
Expand Down
1 change: 0 additions & 1 deletion Sources/UberAuth/Button/LoginButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public final class LoginButton: UberButton {
}

private func logout() {
// TODO: Implement UberAuth.logout()
tokenManager.deleteToken(identifier: Constants.tokenIdentifier)
update()
}
Expand Down
149 changes: 103 additions & 46 deletions Sources/UberAuth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
2. [Setup](#setup)
1. [SDK Configuration](#sdk-configuration)
3. [Authenticating](#authenticating)
1. [Login](#login)
2. [Login Context](#login-context)
3. [Auth Destination](#auth-destination)
1. [Simple Login](#simple-login)
2. [Customized Login](#customized-login)
3. [Auth Destinations](#auth-destinations)
4. [Auth Providers](#auth-providers)
1. [AuthorizationCodeAuthProvider](#wip-authorizationcoreauthprovider)
5. [Prefilling User Information](#wip-prefilling-user-information)
6. [Responding to Redirects](#wip-responding-to-redirects)
1. [Using UIKit](#using-uikit)
2. [Using SwiftUI](#using-swiftui)
7. [Exchanging Authorization Code](#exchanging-authorization-code)
* [AuthorizationCodeAuthProvider](#authorizationcoreauthprovider)
5. [Responding to Redirects](#responding-to-redirects)
* [Using UIKit](#using-uikit)
* [Using SwiftUI](#using-swiftui)
6. [Exchanging Authorization Code](#exchanging-authorization-code)
7. [Prefilling User Information](#prefilling-user-information)
8. [Login Button](#login-button)

# Prerequisites
Expand Down Expand Up @@ -48,7 +48,7 @@ Once registered in the developer portal, add your redirect URI to your Xcode pro
</array>
</dict>
</array>
<key>UberAuth</key>
<key>Uber</key>
<dict>

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

# Authenticating

## Login
## Simple Login
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.

```swift
UberAuth.login { result in
UberAuth.login { result: Result<Client, UberAuthError> in
// Handle result
}
```

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

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


## Login Context
## Customized Login

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:

Expand All @@ -110,7 +110,7 @@ UberAuth.login(
```


## Auth Destination
## Auth Destinations

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

Expand Down Expand Up @@ -140,37 +140,9 @@ UberAuth.login(

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

### [WIP] AuthorizationCoreAuthProvider
### AuthorizationCoreAuthProvider

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).


## [WIP] Prefilling User Information
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.
There are two ways to provide this information:

**Using the LoginButton / DataSource**

WIP

**Using LoginManager Directly**
```
let loginManager = LoginManager(loginType: .authorizationCode)

let prefill = Prefill(
email: "[email protected]",
phoneNumber: "12345678900",
firstName: "Jane",
lastName: "Doe"
)

loginManager.login(
scopes: [.profile],
presentingViewController: viewController,
prefillValues: prefill,
completion: nil
)
```
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.


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

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

## Prefilling User Information
The SDK supports the OpenID `login_hint` parameter for prefilling user information when authenticating with Uber.
To pass user information into the login page, ise the Prefill API when constructing the AuthContext. Partial information is accepted.

**Note:** Prefill information is only supported using the `.inApp` login type.

**Using UberAuth**
```
let prefill = Prefill(
email: "[email protected]",
phoneNumber: "5555555555",
firstName: "Jane",
lastName: "Doe"
)

UberAuth.login(
context: AuthContext(
authDestination: .inApp,
authProvider: .authorizationCode(),
prefill: prefill
),
completion: { _ in }
)
```

**Using the LoginButton / DataSource**

```
final class MyLoginButtonDataSource: LoginButtonDataSource {

func authContext(_ button: LoginButton) -> AuthContext {
let prefill = Prefill(
email: "[email protected]",
phoneNumber: "5555555555",
firstName: "Jane",
lastName: "Doe"
)

return AuthContext(
authDestination: .inApp,
authProvider: .authorizationCode(),
prefill: prefill
)
}
}
```


### Login Button
Coming Soon

As a convenience, the SDK provides a `LoginButton` class that can be used to log a user in or out.

<img src="../../img/login_button.png?raw=true" width=600 alt="Login Button"/>

For simple cases, construct the button using the default initializer.
```
import UberAuth

let loginButton = LoginButton()
```


To receive the login result, conform to the `LoginButtonDelegate`.

```

loginButton.delegate = MyLoginButtonDelegate()

...

final class MyLoginButtonDelegate: LoginButtonDelegate {

func loginButton(_ button: LoginButton, didLogoutWithSuccess success: Bool) {
// Successful logout
}

func loginButton(_ button: LoginButton, didCompleteLoginWithResult result: Result<Client, UberAuthError>) {
switch result {
case .success(let client):
// Handle Client response
break
case .failure(let error):
// Handle UberAuthError
break
}
}
}
```
24 changes: 3 additions & 21 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,9 @@

## Universal Link Sample App

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).
See the [Universal Link Example Readme](./UniversalLinkExample/README.md)

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

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

`universallinkexample://app`

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.
3. [Optional] Install the native Uber app on your device



## SDK Sample Apps

Requires Xcode 9

There are two sample apps, one written in Objective-C, and another written in Swift.

[TODO: Installation instructions]
See the [Universal Link Example Readme](./UberSDK/README.md)
38 changes: 38 additions & 0 deletions examples/UberSDK/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# UberSDK

A sample app demonstrating how to use the Uber iOS SDK.

<img src="../../img/uber_sdk.png?raw=true" width=300 alt="Login Button"/>

## Setup
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/).

## Login
Example usage for the UberAuth login class.

### Auth Type
Specifies the auth grant flow to use for login. Authorization Code is the only option.

### Destination
Sets the auth destination for login. `.inApp` and `.native` are the only options.
If the native Uber app is not installed on the device, `.inApp` is used.

### Exchange Auth Code for Token
Determines if the authorization code should be exchanged locally for an access token

### Always ask for Login
If enabled, the Uber login page will always ask for re-authentication.

### Always ask for Consent
If enabled, the user will always have to agree to linking their account.

### Prefill Values
Allows setting optional values for prefilling user information on the login screen.


## Uber Button
Example usage of the LoginButton convenience UI for login / logout.

## Request a Ride Button
Example usage of the RideRequestButton convenience UI for requesting a ride.
To enable, first log in using either the Login or UberButton section.
16 changes: 16 additions & 0 deletions examples/UniversalLinkExample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Universal Link Example

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).

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

### Setup
1. Add the sample app's redirect URI to your app's configuration in the [Uber Developer Portal](https://developer.uber.com/)

`universallinkexample://app`

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.
3. [Optional] Install the native Uber app on your device
Binary file added img/login_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/uber_sdk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading