Skip to content

Commit

Permalink
Remove remaining parameters parameter (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket authored Dec 21, 2021
1 parent 94787c3 commit 656bab9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 56 deletions.
7 changes: 2 additions & 5 deletions Auth0/Auth0Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,13 @@ struct Auth0Authentication: Authentication {
telemetry: self.telemetry)
}

func startPasswordless(email: String, type: PasswordlessType, connection: String, parameters: [String: Any]) -> Request<Void, AuthenticationError> {
var payload: [String: Any] = [
func startPasswordless(email: String, type: PasswordlessType, connection: String) -> Request<Void, AuthenticationError> {
let payload: [String: Any] = [
"email": email,
"connection": connection,
"send": type.rawValue,
"client_id": self.clientId
]
if case .webLink = type, !parameters.isEmpty {
payload["authParams"] = parameters
}

let start = URL(string: "passwordless/start", relativeTo: self.url)!
return Request(session: session,
Expand Down
34 changes: 15 additions & 19 deletions Auth0/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,24 +246,24 @@ public protocol Authentication: Trackable, Loggable {
}
```

If you need to specify a scope:
You can also specify audience and scope:

```
Auth0
.authentication(clientId: clientId, domain: "samples.auth0.com")
.login(appleAuthorizationCode: authCode,
fullName: credentials.fullName,
scope: "openid profile email offline_access",
audience: "https://myapi.com/api")
audience: "https://myapi.com/api"
scope: "openid profile email offline_access")
.start { print($0) }
```

- Parameters:
- authCode: Authorization Code retrieved from Apple Authorization.
- fullName: The full name property returned with the Apple ID Credentials.
- profile: Additional user profile data returned with the Apple ID Credentials.
- scope: Requested scope value when authenticating the user. By default is `openid profile email`.
- audience: API Identifier that the client is requesting access to.
- authorizationCode: Authorization Code retrieved from Apple Authorization.
- fullName: The full name property returned with the Apple ID Credentials.
- profile: Additional user profile data returned with the Apple ID Credentials.
- audience: API Identifier that the client is requesting access to.
- scope: Requested scope value when authenticating the user. By default is `openid profile email`.
- Returns: A request that will yield Auth0 user's credentials.
*/
func login(appleAuthorizationCode authorizationCode: String, fullName: PersonNameComponents?, profile: [String: Any]?, audience: String?, scope: String) -> Request<Credentials, AuthenticationError>
Expand All @@ -285,22 +285,22 @@ public protocol Authentication: Trackable, Loggable {
}
```

If you need to specify a scope or audience:
You can also specify audience and scope:

```
Auth0
.authentication(clientId: clientId, domain: "samples.auth0.com")
.login(facebookSessionAccessToken: sessionAccessToken,
scope: "openid profile email offline_access",
audience: "https://myapi.com/api")
audience: "https://myapi.com/api"
scope: "openid profile email offline_access")
.start { print($0) }
```

- Parameters:
- sessionAccessToken: Session info Access Token retrieved from Facebook.
- profile: The user profile returned by Facebook.
- scope: Requested scope value when authenticating the user. By default is `openid profile email`.
- audience: API Identifier that the client is requesting access to.
- scope: Requested scope value when authenticating the user. By default is `openid profile email`.
- Returns: A request that will yield Auth0 user's credentials.
*/
func login(facebookSessionAccessToken sessionAccessToken: String, profile: [String: Any], audience: String?, scope: String) -> Request<Credentials, AuthenticationError>
Expand Down Expand Up @@ -442,7 +442,7 @@ public protocol Authentication: Trackable, Loggable {
- Returns: A request.
- Requires: Passwordless OTP Grant `http://auth0.com/oauth/grant-type/passwordless/otp`. Check [our documentation](https://auth0.com/docs/configure/applications/application-grant-types) for more information and how to enable it.
*/
func startPasswordless(email: String, type: PasswordlessType, connection: String, parameters: [String: Any]) -> Request<Void, AuthenticationError>
func startPasswordless(email: String, type: PasswordlessType, connection: String) -> Request<Void, AuthenticationError>

/**
Starts passwordless authentication by sending an sms with an OTP code.
Expand Down Expand Up @@ -631,12 +631,8 @@ public extension Authentication {
return self.signup(email: email, username: username, password: password, connection: connection, userMetadata: userMetadata, rootAttributes: rootAttributes)
}

func signup(email: String, username: String? = nil, password: String, connection: String, userMetadata: [String: Any]? = nil) -> Request<DatabaseUser, AuthenticationError> {
return self.signup(email: email, username: username, password: password, connection: connection, userMetadata: userMetadata, rootAttributes: nil)
}

func startPasswordless(email: String, type: PasswordlessType = .code, connection: String = "email", parameters: [String: Any] = [:]) -> Request<Void, AuthenticationError> {
return self.startPasswordless(email: email, type: type, connection: connection, parameters: parameters)
func startPasswordless(email: String, type: PasswordlessType = .code, connection: String = "email") -> Request<Void, AuthenticationError> {
return self.startPasswordless(email: email, type: type, connection: connection)
}

func startPasswordless(phoneNumber: String, type: PasswordlessType = .code, connection: String = "sms") -> Request<Void, AuthenticationError> {
Expand Down
32 changes: 0 additions & 32 deletions Auth0Tests/AuthenticationSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -829,38 +829,6 @@ class AuthenticationSpec: QuickSpec {
}
}

it("should start with email and authParameters for web link") {
let params = ["scope": "openid"]
stub(condition: isPasswordless(Domain) && hasAtLeast(["email": SupportAtAuth0]) && hasObjectAttribute("authParams", value: params)) { _ in return passwordless(SupportAtAuth0, verified: true) }.name = "email passwordless web link with parameters"
waitUntil(timeout: Timeout) { done in
auth.startPasswordless(email: SupportAtAuth0, type: .webLink, parameters: params).start { result in
expect(result).to(beSuccessful())
done()
}
}
}

it("should not send params if type is not web link") {
let params = ["scope": "openid"]
stub(condition: isPasswordless(Domain) && hasAllOf(["email": SupportAtAuth0, "connection": "email", "client_id": ClientId, "send": "code"])) { _ in return passwordless(SupportAtAuth0, verified: true) }.name = "email passwordless without parameters"
waitUntil(timeout: Timeout) { done in
auth.startPasswordless(email: SupportAtAuth0, type: .code, parameters: params).start { result in
expect(result).to(beSuccessful())
done()
}
}
}

it("should not add params attr if they are empty") {
stub(condition: isPasswordless(Domain) && hasAllOf(["email": SupportAtAuth0, "connection": "email", "client_id": ClientId, "send": "code"])) { _ in return passwordless(SupportAtAuth0, verified: true) }.name = "email passwordless without parameters"
waitUntil(timeout: Timeout) { done in
auth.startPasswordless(email: SupportAtAuth0, type: .code, parameters: [:]).start { result in
expect(result).to(beSuccessful())
done()
}
}
}

it("should fail to start") {
stub(condition: isPasswordless(Domain)) { _ in return authFailure(error: "error", description: "description") }.name = "failed passwordless start"
waitUntil(timeout: Timeout) { done in
Expand Down
1 change: 1 addition & 0 deletions V2_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ The following methods lost the `parameters` parameter:
- `login(phoneNumber:code:audience:scope:)`
- `login(usernameOrEmail:password:realmOrConnection:audience:scope:)`
- `loginDefaultDirectory(withUsername:password:audience:scope:)`
- `startPasswordless(email:type:connection:)`

To pass custom parameters to those (or any) method in the Authentication client, use the `parameters(_:)` method from `Request`:

Expand Down

0 comments on commit 656bab9

Please sign in to comment.