Skip to content

Commit

Permalink
Merge pull request #98 from auth0/feature_webauth_spawn
Browse files Browse the repository at this point in the history
Authentication can now create WebAuth instances for given connection
  • Loading branch information
hzalaz authored Mar 13, 2017
2 parents df490d4 + 4fb1f12 commit 7a11096
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
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"
}
}

}
}

0 comments on commit 7a11096

Please sign in to comment.