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

Remove Web Auth method embedded in Authentication API client #560

Merged
merged 2 commits into from
Dec 1, 2021
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
11 changes: 0 additions & 11 deletions Auth0/Auth0WebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,5 @@ final class Auth0WebAuth: WebAuth {
organization: self.organization)
}

}

extension Auth0Authentication {

func webAuth(withConnection connection: String) -> WebAuth {
let webAuth = Auth0WebAuth(clientId: self.clientId, url: self.url, telemetry: self.telemetry)
return webAuth
.logging(enabled: self.logger != nil)
.connection(connection)
}

}
#endif
26 changes: 0 additions & 26 deletions Auth0/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -486,32 +486,6 @@ public protocol Authentication: Trackable, Loggable {
*/
func jwks() -> Request<JWKS, AuthenticationError>

#if WEB_AUTH_PLATFORM
/**
Creates a new WebAuth request to authenticate using Safari browser and OAuth authorize flow.

With the connection name Auth0 will redirect to the associated IdP login page to authenticate

```
Auth0
.authentication(clientId: clientId, domain: "samples.auth0.com")
.webAuth(withConnection: "facebook")
.start { print($0) }
```

If you need to show your Auth0 account login page just create the WebAuth object directly

```
Auth0
.webAuth(clientId: clientId, domain: "samples.auth0.com")
.start { print($0) }
```

- parameter connection: name of the connection to use
- returns: a newly created WebAuth object.
*/
func webAuth(withConnection connection: String) -> WebAuth
#endif
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Auth0/CredentialsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public protocol CredentialsStorage {
/// - forKey: The key to get from the store
/// - Returns: The stored data
func getEntry(forKey: String) -> Data?

/// Set a storage entry
///
/// - Parameters:
/// - _: The data to be stored
/// - forKey: The key to store it to
/// - Returns: if credentials were stored
func setEntry(_: Data, forKey: String) -> Bool

/// Delete a storage entry
///
/// - Parameters:
Expand Down
21 changes: 0 additions & 21 deletions Auth0Tests/AuthenticationSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1073,26 +1073,5 @@ class AuthenticationSpec: QuickSpec {
}
}

#if WEB_AUTH_PLATFORM
describe("spawn WebAuth instance") {

it("should return a WebAuth instance with matching credentials") {
let webAuth = auth.webAuth(withConnection: "facebook")
expect(webAuth.clientId) == auth.clientId
expect(webAuth.url) == auth.url
}

it("should return a WebAuth instance with matching telemetry") {
let webAuth = auth.webAuth(withConnection: "facebook") as! Auth0WebAuth
expect(webAuth.telemetry.info) == auth.telemetry.info
}

it("should return a WebAuth instance with matching connection") {
let webAuth = auth.webAuth(withConnection: "facebook") as! Auth0WebAuth
expect(webAuth.parameters["connection"]) == "facebook"
}
}
#endif

}
}
11 changes: 4 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import PackageDescription

var webAuthPlatforms: [Platform] = [.iOS, .macOS]

#if swift(>=5.5)
webAuthPlatforms.append(.macCatalyst)
let webAuthPlatforms: [Platform] = [.iOS, .macOS, .macCatalyst]
#else
let webAuthPlatforms: [Platform] = [.iOS, .macOS]
#endif

let webAuthFlag = "WEB_AUTH_PLATFORM"
let webAuthCondition: BuildSettingCondition = .when(platforms: webAuthPlatforms)
let swiftSettings: [SwiftSetting] = [.define(webAuthFlag, webAuthCondition)]
let swiftSettings: [SwiftSetting] = [.define("WEB_AUTH_PLATFORM", .when(platforms: webAuthPlatforms))]

let package = Package(
name: "Auth0",
Expand Down
50 changes: 33 additions & 17 deletions V2_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The custom `Result` enum has been removed, along with its shims. Auth0.swift is

### Structs

The following structs have been removed, as they are no longer in use:
The following structs were removed, as they were no longer being used:

- `NativeAuthCredentials`
- `ConcatRequest`
Expand All @@ -74,7 +74,7 @@ The following Objective-C compatibility wrappers have been removed:
- `_ObjectiveManagementAPI`
- `_ObjectiveOAuth2`

The following classes were also removed, as they are no longer in use:
The following classes were also removed, as they were no longer being used:

- `Profile`
- `Identity`
Expand All @@ -101,6 +101,20 @@ Use `userInfo(withAccessToken:)` instead.

Use `login(appleAuthorizationCode:fullName:profile:audience:scope:)` instead.

#### `webAuth(withConnection:)`

Use Web Auth with its `connection(_:)` method instead:

```swift
Auth0.webAuth()
.connection("some-connection")
.start { result in
// ...
}
```

#### Other methods

The following methods have been removed and have no replacement, as they rely on deprecated endpoints:

- `loginSocial(token:connection:scope:parameters:)`
Expand Down Expand Up @@ -155,21 +169,21 @@ The `a0_url(_:)` method is no longer public.

#### Properties removed

- `info: [String: Any]` is no longer public. Use the new subscript to access its values straight from the error; e.g. `error["code"]`.
`info: [String: Any]` is no longer public. Use the new subscript to access its values straight from the error; e.g. `error["code"]`.

#### Properties renamed

- `description` was renamed to `localizedDescription`, as `AuthenticationError` now conforms to `CustomStringConvertible`.
`description` was renamed to `localizedDescription`, as `AuthenticationError` now conforms to `CustomStringConvertible`.

### `ManagementError` struct

#### Properties removed

- `info: [String: Any]` is no longer public. Use the new subscript to access its values straight from the error; e.g. `error["code"]`.
`info: [String: Any]` is no longer public. Use the new subscript to access its values straight from the error; e.g. `error["code"]`.

#### Properties renamed

- `description` was renamed to `localizedDescription`, as `ManagementError` now conforms to `CustomStringConvertible`.
`description` was renamed to `localizedDescription`, as `ManagementError` now conforms to `CustomStringConvertible`.

### `WebAuthError` struct

Expand All @@ -179,7 +193,7 @@ All the former enum cases are now static properties, so to switch over them you

```swift
switch error {
case .userCancelled: // handle error
case .userCancelled: handleError(error)
// ...
}
```
Expand All @@ -188,7 +202,7 @@ switch error {

```swift
switch error {
case .userCancelled: // handle error
case .userCancelled: handleError(error)
// ...
default: // handle unknown errors, e.g. errors added in future versions
}
Expand All @@ -203,6 +217,8 @@ switch error {

#### Error cases removed

All the following error cases were no longer being used.

- `.noNonceProvided`
- `.invalidIdTokenNonce`
- `.cannotDismissWebAuthController`
Expand All @@ -216,10 +232,10 @@ switch error {

#### Error cases added

- `.malformedInvitationURL`
- `.noAuthorizationCode`
- `.idTokenValidationFailed`
- `.other`
- `.malformedInvitationURL`, for when the invitation URL is missing the `organization` and/or the `invitation` query parameters.
- `.noAuthorizationCode`, for when the callback URL is missing the `code` query parameter.
- `.idTokenValidationFailed`, for when the ID Token validation performed after Web Auth login fails.
- `.other`, for when a different `Error` happens. That error can be acessed via the `cause: Error?` property.

### `CredentialsManagerError` struct

Expand Down Expand Up @@ -252,7 +268,7 @@ switch error {

#### Error cases added

- `.largeMinTTL`
`.largeMinTTL`, for when the requested `minTTL` is greater than the lifetime of the renewed Access Token.

### `UserInfo` struct

Expand Down Expand Up @@ -299,7 +315,7 @@ Auth0
.tokenExchange() // Returns a Request
.parameters(["key": "value"]) // 👈🏻
.start { result in
print(result)
// ...
}
```

Expand Down Expand Up @@ -382,15 +398,15 @@ credentialsManager.credentials { error, credentials in
guard error == nil, let credentials = credentials else {
return handleError(error)
}
... // credentials retrieved
// credentials retrieved
```

##### After

```swift
credentialsManager.credentials { result in
switch result {
case .success(let credentials): ... // credentials retrieved
case .success(let credentials): // credentials retrieved
case .failure(let error): handleError(error)
}
}
Expand All @@ -407,7 +423,7 @@ Auth0
.webAuth()
.scope("profile email") // "openid profile email" will be used
.start { result in
print(result)
// ...
}
```

Expand Down