Using Lock credentials aren't not being saved on emulator.
scottandrew opened this issue · 2 comments
Please do not report security vulnerabilities here. The Responsible Disclosure Program details the procedure for disclosing security issues.
Thank you in advance for helping us to improve this library! Please read through the template below and answer all relevant questions. Your additional work here is greatly appreciated and will help us respond as quickly as possible. For general support or usage questions, use the Auth0 Community or Auth0 Support. Finally, to avoid duplicates, please search existing Issues before submitting one here.
By submitting an Issue to this repository, you agree to the terms within the Auth0 Code of Conduct.
Description
I have a simple service that authenticates using Lock. When the authentication is complete the credentials are written using CredentialManager. However if check to see if there are valid credentials using hasValid() it always returns false.
The auth0 session sample seems to work fine.
Reproduction
public enum AuthenticationServiceError: Error {
case failedToGetToken
case failedToSaveToken
case failedToLogout
}
typealias AuthenticationServiceResult = Swift.Result<Void, AuthenticationServiceError>
class Auth0Service {
private (set) var token: String?
private let credentialsManager: CredentialsManager = CredentialsManager(authentication: Auth0.authentication(), storage: A0SimpleKeychain())
enum State {
case loggedIn
case loggedOut
}
private var credentials: Credentials?
private (set) var state: State = .loggedOut
var isTokenValid: Bool { return credentialsManager.hasValid() }
init() {
// lets turn on logging
_ = Auth0.authentication().logging(enabled: true)
}
func login(handler: @escaping (AuthenticationServiceResult) -> Void) {
if isTokenValid {
credentialsManager.credentials { error, credentials in
guard let credentials = credentials else {
self.state = .loggedOut
self.token = nil
if let error = error { print("\(error)")}
handler(AuthenticationServiceResult.failure(.failedToGetToken))
return
}
self.token = credentials.accessToken
handler(AuthenticationServiceResult.success(()))
}
} else {
Lock
.classic()
.withOptions { options in
options.scope = "openid profile offline_access"
options.audience = "https://test-brighloom-cantina.auth0.com/userinfo"
options.oidcConformant = true
options.logHttpRequest = true
options.logLevel = .all
}
.withConnections {
$0.database(name: "Username-Password-Authentication", requiresUsername: true)
}
.onAuth { [weak self] credentials in
self?.credentials = credentials
if !(self?.credentialsManager.store(credentials: credentials) ?? false) {
handler(AuthenticationServiceResult.failure(.failedToSaveToken))
}
handler(AuthenticationServiceResult.success(()))
}
.onError { error in
handler(Swift.Result<Void, AuthenticationServiceError>.failure(.failedToGetToken))
}
.present(from: UIApplication.shared.windows.first!.rootViewController!)
}
}
}
Environment
Please provide the following:
- Lock 2.16.1
- Xcode 11.3, iOS 13.3
Actually this is a problem in 11.4 beta 3 and iOS 11.4 simulator.
Same issue as auth0/SimpleKeychain#90, please check that thread for updates.