Skip to content

Commit

Permalink
Added webAuth method to Authentication, spawn new WebAuth instance
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
cocojoe committed Mar 7, 2017
1 parent df490d4 commit da05010
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Auth0/Auth0Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,8 @@ struct Auth0Authentication: Authentication {
let delegation = URL(string: "/delegation", relativeTo: self.url)!
return Request(session: session, url: delegation, method: "POST", handle: plainJson, payload: payload, logger: self.logger, telemetry: self.telemetry)
}

func webAuth(withConnection connection: String) -> WebAuth {
return SafariWebAuth(clientId: self.clientId, url: self.url, presenter: ControllerModalPresenter(), telemetry: self.telemetry).connection(connection)
}
}
34 changes: 34 additions & 0 deletions Auth0/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,22 @@ public protocol Authentication: Trackable, Loggable {
- returns: a request that will yield the result of delegation
*/
func delegation(withParameters parameters: [String: Any]) -> Request<[String: Any], AuthenticationError>

/**
Creates a new WebAuth compliant instance using authentication credentials
and telemetry.

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

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

/**
Expand Down Expand Up @@ -682,4 +698,22 @@ public extension Authentication {
public func loginSocial(token: String, connection: String, scope: String = "openid", parameters: [String: Any] = [:]) -> Request<Credentials, AuthenticationError> {
return self.loginSocial(token: token, connection: connection, scope: scope, parameters: parameters)
}

/**
Creates a new WebAuth compliant instance using authentication credentials
and telemetry.

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

- parameter connection: name of the connection to use.
- returns: a newly created WebAuth compliant object.
*/
public func webAuth(withConnection connection: String) -> WebAuth {
return self.webAuth(withConnection: connection)
}
}
14 changes: 14 additions & 0 deletions Auth0Tests/AuthenticationSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,19 @@ class AuthenticationSpec: QuickSpec {

}

describe("spawn WebAuth instance") {

it("should return a WebAuth instance with matching authentication 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 connection") {
let webAuth = auth.webAuth(withConnection: "facebook") as! SafariWebAuth
expect(webAuth.parameters["connection"]) == "facebook"
}
}

}
}

0 comments on commit da05010

Please sign in to comment.