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

Feature MFA support for password-realm (On Hold) #81

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion Auth0/Auth0Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Auth0Authentication: Authentication {
return Request(session: session, url: resourceOwner, method: "POST", handle: authenticationObject, payload: payload, logger: self.logger, telemetry: self.telemetry)
}

func login(usernameOrEmail username: String, password: String, realm: String, audience: String?, scope: String?) -> Request<Credentials, AuthenticationError> {
func login(usernameOrEmail username: String, password: String, realm: String, audience: String?, scope: String?, multifactorCode: String?) -> Request<Credentials, AuthenticationError> {
let resourceOwner = URL(string: "/oauth/token", relativeTo: self.url)!
var payload: [String: Any] = [
"username": username,
Expand All @@ -63,6 +63,7 @@ struct Auth0Authentication: Authentication {
]
payload["audience"] = audience
payload["scope"] = scope
payload["mfa_code"] = multifactorCode
return Request(session: session, url: resourceOwner, method: "POST", handle: authenticationObject, payload: payload, logger: self.logger, telemetry: self.telemetry)
}

Expand Down
8 changes: 5 additions & 3 deletions Auth0/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ public protocol Authentication: Trackable, Loggable {
- parameter realm: domain of the realm or connection name
- parameter audience: API Identifier that the client is requesting access to.
- parameter scope: scope value requested when authenticating the user.
- paramater multifactoreCode: multifactor code if the user has enrolled one.
- important: This only works if you have the OAuth 2.0 API Authorization flag on
- returns: authentication request that will yield Auth0 User Credentials
*/
func login(usernameOrEmail username: String, password: String, realm: String, audience: String?, scope: String?) -> Request<Credentials, AuthenticationError>
func login(usernameOrEmail username: String, password: String, realm: String, audience: String?, scope: String?, multifactorCode: String?) -> Request<Credentials, AuthenticationError>

/**
Creates a user in a Database connection
Expand Down Expand Up @@ -494,10 +495,11 @@ public extension Authentication {
- parameter realm: domain realm or connection name
- parameter audience: API Identifier that the client is requesting access to.
- parameter scope: scope value requested when authenticating the user.
- paramater multifactorCode: multifactor code if the user has enrolled one.
- Returns: authentication request that will yield Auth0 User Credentials
*/
public func login(usernameOrEmail username: String, password: String, realm: String, audience: String? = nil, scope: String? = nil) -> Request<Credentials, AuthenticationError> {
return self.login(usernameOrEmail: username, password: password, realm: realm, audience: audience, scope: scope)
public func login(usernameOrEmail username: String, password: String, realm: String, audience: String? = nil, scope: String? = nil, multifactorCode: String? = nil) -> Request<Credentials, AuthenticationError> {
return self.login(usernameOrEmail: username, password: password, realm: realm, audience: audience, scope: scope, multifactorCode: multifactorCode)
}


Expand Down
10 changes: 10 additions & 0 deletions Auth0Tests/AuthenticationSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ class AuthenticationSpec: QuickSpec {
}
}
}

it("should specify realm, scope and multifactor code in request") {
stub(condition: isToken(Domain) && hasAtLeast(["username":SupportAtAuth0, "password": ValidPassword, "scope": "openid", "mfa_code" : "123456789", "realm" : "customconnection"])) { _ in return authResponse(accessToken: AccessToken) }.name = "Grant Password Custom audience, scope and realm"
waitUntil(timeout: Timeout) { done in
auth.login(usernameOrEmail: SupportAtAuth0, password: ValidPassword, realm: "customconnection", scope: "openid", multifactorCode: "123456789").start { result in
expect(result).to(haveCredentials())
done()
}
}
}

}

Expand Down