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

Compatibility updates against latest Auth0.Swift #356

Merged
merged 5 commits into from
Dec 16, 2016
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
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3
3.0
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
reference: http://www.objc.io/issue-6/travis-ci.html
language: objective-c
osx_image: xcode8.1
osx_image: xcode8.2
before_install: true
install: true
script:
Expand Down
3 changes: 1 addition & 2 deletions App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return Lock.resumeAuth(url, options: options)
}

}

2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "auth0/Auth0.swift" ~> 1.0
github "auth0/Auth0.swift" ~> 1.1
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "auth0/Auth0.swift" "1.0.1"
github "auth0/Auth0.swift" "1.1.0"
github "emaloney/CleanroomASL" "2.0.0"
github "Quick/Nimble" "v5.1.1"
github "AliSoftware/OHHTTPStubs" "5.2.2-swift3"
Expand Down
6 changes: 3 additions & 3 deletions Lock/EnterpriseDomainInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ struct EnterpriseDomainInteractor: HRDAuthenticatable {
let emailValidator: InputValidator = EmailValidator()
let authenticator: OAuth2Authenticatable

init(connections: [EnterpriseConnection], authentication: OAuth2Authenticatable) {
self.connections = connections
init(connections: Connections, authentication: OAuth2Authenticatable) {
self.connections = connections.enterprise
self.authenticator = authentication

// Single Enterprise, defaulting connection
if self.connections.count == 1 {
if self.connections.count == 1 && connections.oauth2.isEmpty && connections.database == nil {
self.connection = self.connections.first
}
}
Expand Down
4 changes: 2 additions & 2 deletions Lock/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ class Router: Navigable {
// Add Enterprise
if !connections.enterprise.isEmpty {
let authInteractor = Auth0OAuth2Interactor(webAuth: self.lock.webAuth, onCredentials: self.onAuthentication, options: self.lock.options)
let interactor = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: authInteractor)
let interactor = EnterpriseDomainInteractor(connections: connections, authentication: authInteractor)
presenter.enterpriseInteractor = interactor
}
return presenter
}
if !connections.enterprise.isEmpty {
let authInteractor = Auth0OAuth2Interactor(webAuth: self.lock.webAuth, onCredentials: self.onAuthentication, options: self.lock.options)
let interactor = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: authInteractor)
let interactor = EnterpriseDomainInteractor(connections: connections, authentication: authInteractor)
// Single enterprise in active auth mode
if let connection = interactor.connection, self.lock.options.enterpriseConnectionUsingActiveAuth.contains(connection.name) {
return EnterpriseActiveAuth(connection)
Expand Down
12 changes: 6 additions & 6 deletions LockTests/Interactors/EnterpriseDomainInteractorSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class EnterpriseDomainInteractorSpec: QuickSpec {
credentials = nil
webAuth = MockWebAuth()
authentication = Auth0OAuth2Interactor(webAuth: webAuth, onCredentials: {credentials = $0}, options: LockOptions())
enterprise = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: authentication)
enterprise = EnterpriseDomainInteractor(connections: connections, authentication: authentication)
}

afterEach {
Expand All @@ -69,7 +69,7 @@ class EnterpriseDomainInteractorSpec: QuickSpec {
connections = OfflineConnections()
connections.enterprise(name: "TestAD", domains: [])

enterprise = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: authentication)
enterprise = EnterpriseDomainInteractor(connections: connections, authentication: authentication)
}

it("connection should not default to single connection") {
Expand All @@ -87,7 +87,7 @@ class EnterpriseDomainInteractorSpec: QuickSpec {
beforeEach {
connections = OfflineConnections()
connections.enterprise(name: "TestAD", domains: [])
enterprise = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: authentication)
enterprise = EnterpriseDomainInteractor(connections: connections, authentication: authentication)
}

it("should raise no error but no connection provided") {
Expand All @@ -102,7 +102,7 @@ class EnterpriseDomainInteractorSpec: QuickSpec {
beforeEach {
connections = OfflineConnections()
connections.enterprise(name: "TestAD", domains: ["test.com"])
enterprise = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: authentication)
enterprise = EnterpriseDomainInteractor(connections: connections, authentication: authentication)
}

it("should match email domain") {
Expand Down Expand Up @@ -137,7 +137,7 @@ class EnterpriseDomainInteractorSpec: QuickSpec {
connections = OfflineConnections()
connections.enterprise(name: "TestAD", domains: ["test.com","pepe.com"])

enterprise = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: authentication)
enterprise = EnterpriseDomainInteractor(connections: connections, authentication: authentication)
}

it("should match first email domain and provide enteprise connection") {
Expand All @@ -162,7 +162,7 @@ class EnterpriseDomainInteractorSpec: QuickSpec {

connections = OfflineConnections()
connections.enterprise(name: "TestAD", domains: ["test.com"])
enterprise = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: authentication)
enterprise = EnterpriseDomainInteractor(connections: connections, authentication: authentication)
}

it("should fail to launch on no valid connection") {
Expand Down
6 changes: 3 additions & 3 deletions LockTests/Presenters/DatabasePresenterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DatabasePresenterSpec: QuickSpec {
oauth2 = MockOAuth2()
connections = OfflineConnections()

enterpriseInteractor = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: oauth2)
enterpriseInteractor = EnterpriseDomainInteractor(connections: connections, authentication: oauth2)
authPresenter = MockAuthPresenter(connections: connections, interactor: MockAuthInteractor(), customStyle: [:])
messagePresenter = MockMessagePresenter()
interactor = MockDBInteractor()
Expand Down Expand Up @@ -541,7 +541,7 @@ class DatabasePresenterSpec: QuickSpec {
connections = OfflineConnections()
connections.enterprise(name: "validAD", domains: ["valid.com"])

enterpriseInteractor = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: oauth2)
enterpriseInteractor = EnterpriseDomainInteractor(connections: connections, authentication: oauth2)
presenter.enterpriseInteractor = enterpriseInteractor

view = presenter.view as! DatabaseOnlyView
Expand Down Expand Up @@ -635,7 +635,7 @@ class DatabasePresenterSpec: QuickSpec {
connections.enterprise(name: "validAD", domains: ["valid.com"])

presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
enterpriseInteractor = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: oauth2)
enterpriseInteractor = EnterpriseDomainInteractor(connections: connections, authentication: oauth2)
presenter.enterpriseInteractor = enterpriseInteractor

view = presenter.view as! DatabaseOnlyView
Expand Down
6 changes: 3 additions & 3 deletions LockTests/Presenters/EnterpriseDomainPresenterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class EnterpriseDomainPresenterSpec: QuickSpec {
connections.enterprise(name: "TestAD", domains: ["test.com"])
connections.enterprise(name: "ValidAD", domains: ["validad.com"])

interactor = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: oauth2)
interactor = EnterpriseDomainInteractor(connections: connections, authentication: oauth2)
presenter = EnterpriseDomainPresenter(interactor: interactor, navigator: navigator, user: user, options: options)
presenter.messagePresenter = messagePresenter
view = presenter.view as! EnterpriseDomainView
Expand Down Expand Up @@ -82,7 +82,7 @@ class EnterpriseDomainPresenterSpec: QuickSpec {
connections = OfflineConnections()
connections.enterprise(name: "TestAD", domains: ["test.com"])

interactor = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: oauth2)
interactor = EnterpriseDomainInteractor(connections: connections, authentication: oauth2)
presenter = EnterpriseDomainPresenter(interactor: interactor, navigator: navigator, user: user, options: options)
presenter.messagePresenter = messagePresenter
view = presenter.view as! EnterpriseDomainView
Expand Down Expand Up @@ -252,7 +252,7 @@ class EnterpriseDomainPresenterSpec: QuickSpec {
connections = OfflineConnections()
connections.enterprise(name: "TestAD", domains: ["test.com"])

interactor = EnterpriseDomainInteractor(connections: connections.enterprise, authentication: oauth2)
interactor = EnterpriseDomainInteractor(connections: connections, authentication: oauth2)
presenter = EnterpriseDomainPresenter(interactor: interactor, navigator: navigator, user: user, options: options)
presenter.messagePresenter = messagePresenter
view = presenter.view as! EnterpriseDomainView
Expand Down
12 changes: 12 additions & 0 deletions LockTests/Utils/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ class MockWebAuth: WebAuth {
callback(self.result())
}

func responseType(_ response: [ResponseType]) -> Self {
return self
}

func nonce(_ nonce: String) -> Self {
return self
}

func audience(_ audience: String) -> Self {
return self
}

var logger: Auth0.Logger? = nil
}

Expand Down
52 changes: 25 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@ Lock makes it easy to integrate SSO in your app. You won't have to worry about:

- iOS 9 or later
- Xcode 8
- Swift 2.3
- Swift 3.0

## Install

### Carthage

In your cartfile add
In your `Cartfile` add

```
github "auth0/Lock.iOS-OSX" "2.0.0-beta.2"
github "auth0/Lock.iOS-OSX" "2.0.0-beta.3"
```

## Usage

First to import **Lock.swift**
First import **Lock.swift**

```swift
import Lock
```

then in your `AppDelegate.swift` add the following
Next in your `AppDelegate.swift` add the following:

```swift
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
return Lock.resumeAuth(url, options: options)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return Lock.resumeAuth(url, options: options)
}
```

### Configuration

In order to use Lock you need to provide your Auth0 Client Id and Domain, either with a *Property List* file
In order to use Lock you need to provide your Auth0 Client Id and Domain.

> Auth0 ClientId & Domain can be found in your [Auth0 Dashboard](https://manage.auth0.com)

Expand All @@ -69,30 +69,25 @@ In your application bundle you can add a `plist` file named `Auth0.plist` with t
</plist>
```

### Classic
### Classic

Lock Classic handles authentication using Database, Social & Enterprise connections.

> Currenty Lock.swift only supports Database & Social authentication and you need to tell Lock what connections it should use

To show **Lock.swift**, add the following snippet in any of your `UIViewController`

```swift
Lock
.classic()
.connections {
$0.database(name: "Username-Password-Authentication", requiresUsername: true)
}
.options {
.withOptions {
$0.closable = false
}
.on { result in
switch result {
case .Success(let credentials):
case .success(let credentials):
print("Obtained credentials \(credentials)")
case .Failure(let cause):
case .failure(let cause):
print("Failed with \(cause)")
case .Cancelled:
case .cancelled:
print("User cancelled")
}
}
Expand All @@ -101,26 +96,29 @@ Lock

#### Specify Connections

> Eventually **Lock.swift** will be able to load your client configuration automatically, but until then you should describe what connections it should use.
**Lock.swift** will automatically load your client configuration automatically, if you wish to override this you can manually specify which of your connections to use.

Before presenting **Lock.swift** you can tell it what connections it should display and use to authenticate an user. You can do that by calling the method and supply a closure that can specify the connections.

Before presenting **Lock.swift** you can tell it what connections it should display and use to authenticate an user. You can do that by calling the method and supply a closure that can specify the connections
Adding a database connection:

```swift
.connections { connections in
// Your connections
.withConnections {
$0.database(name: "Username-Password-Authentication", requiresUsername: true)
}
```

So if you need a database connection you can call
Adding multiple social connections:

```swift
connections.database(name: "{CONNECTION_NAME}", requiresUsername: true)
```

Or a social connection

```swift
connections.social(name: "{CONNECTION_NAME}", style: .Facebook)
.withConnections { connections in
connections.social(name: "facebook", style: .Facebook)
connections.social(name: "google-oauth2", style: .Google)
}
```

### Logging
Expand All @@ -130,7 +128,7 @@ In **Lock.swift** options you can turn on/off logging capabilities
```swift
Lock
.classic()
.options {
.withOptions {
$0.logLevel = .All
$0.logHttpRequest = true
}
Expand Down
2 changes: 1 addition & 1 deletion script/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

REQUIRED_CARTHAGE_VERSION=0.18.1
REQUIRED_SWIFTLINT_VERSION=0.13.0
REQUIRED_SWIFTLINT_VERSION=0.13.2
CARTHAGE_BUILD_PLATFORM=${CARTHAGE_BUILD_PLATFORM:-"iOS"}
CARTHAGE_NO_USE_BINARIES=${CARTHAGE_NO_USE_BINARIES:-"true"}
PROJECT_NAME=Lock
Expand Down