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

Authentication can now create WebAuth instances for given connection #98

Merged
merged 2 commits into from
Mar 13, 2017
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
7 changes: 7 additions & 0 deletions Auth0/Auth0Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,11 @@ 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 {
var safari = SafariWebAuth(clientId: self.clientId, url: self.url, presenter: ControllerModalPresenter(), telemetry: self.telemetry)
return safari
.logging(enabled: self.logger != nil)
.connection(connection)
}
}
25 changes: 25 additions & 0 deletions Auth0/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,31 @@ 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 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
}

/**
Expand Down
19 changes: 19 additions & 0 deletions Auth0Tests/AuthenticationSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,24 @@ class AuthenticationSpec: QuickSpec {

}

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! SafariWebAuth
expect(webAuth.telemetry.info) == auth.telemetry.info
}

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

}
}