Skip to content

Commit

Permalink
fix version update bug
Browse files Browse the repository at this point in the history
Fix a bug that prevented sign in after the app version was updated
  • Loading branch information
motyd authored Jun 19, 2018
1 parent 5ecc28c commit c5567f6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IBM Cloud App ID iOS Swift SDK

[![IBM Cloud powered][img-ibmcloud-powered]][url-ibmcloud]
[![Travis][img-travis-master]][url-travis-master]
[![Coveralls][img-coveralls-master]][url-coveralls-master]
Expand Down Expand Up @@ -301,3 +301,4 @@ This package contains code licensed under the Apache License, Version 2.0 (the "

[img-codacy]: https://api.codacy.com/project/badge/Grade/d41f8f069dd343769fcbdb55089561fc
[url-codacy]: https://www.codacy.com/app/ibm-cloud-security/appid-clientsdk-swift

10 changes: 2 additions & 8 deletions Source/IBMCloudAppID/internal/AppIDConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,8 @@ internal class AppIDConstants {

internal static let AnonymousIdpName = "appid_anon"
internal static let BMSSecurityErrorDomain = "com.ibm.mobilefirstplatform.clientsdk.swift.bmssecurity"
internal static let privateKeyIdentifier = "\(_PRIVATE_KEY_LABEL):\(nameAndVer.name):\(nameAndVer.version)"
internal static let publicKeyIdentifier = "\(_PUBLIC_KEY_LABEL):\(nameAndVer.name):\(nameAndVer.version)"
internal static let idTokenLabel = "\(OAUTH_ID_TOKEN_LABEL):\(nameAndVer.name):\(nameAndVer.version)"
internal static let accessTokenLabel = "\(OAUTH_ACCESS_TOKEN_LABEL):\(nameAndVer.name):\(nameAndVer.version)"
internal static let clientIdLabel = "\(CLIENT_ID_KEY_LABEL):\(nameAndVer.name):\(nameAndVer.version)"
internal static let tenantIdLabel = "\(TENANT_ID_KEY_LABEL):\(nameAndVer.name):\(nameAndVer.version)"
internal static let certificateIdentifier = "\(OAUTH_CERT_LABEL):\(nameAndVer.name):\(nameAndVer.version)"
internal static let AuthorizationKeyChainTagsDictionary = [privateKeyIdentifier : kSecClassKey, publicKeyIdentifier : kSecClassKey, idTokenLabel : kSecClassGenericPassword, accessTokenLabel : kSecClassGenericPassword, certificateIdentifier : kSecClassCertificate]
internal static let privateKeyIdentifier = "\(_PRIVATE_KEY_LABEL):\(nameAndVer.name)"
internal static let publicKeyIdentifier = "\(_PUBLIC_KEY_LABEL):\(nameAndVer.name)"
internal static let localeParamName = "language"

}
11 changes: 9 additions & 2 deletions Source/IBMCloudAppID/internal/RegistrationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class RegistrationManager {
public func ensureRegistered(callback : @escaping (AppIDError?) -> Void) {
let storedClientId:String? = self.getRegistrationDataString(name: AppIDConstants.client_id_String)
let storedTenantId:String? = self.preferenceManager.getStringPreference(name: AppIDConstants.tenantPrefName).get()
if storedClientId != nil && self.appId.tenantId == storedTenantId {
if storedClientId != nil && self.appId.tenantId == storedTenantId && privateKeyExist() {
RegistrationManager.logger.debug(message: "OAuth client is already registered.")
callback(nil)
} else {
Expand All @@ -44,7 +44,15 @@ internal class RegistrationManager {
callback(nil)
})
}
}

internal func privateKeyExist() -> Bool {
do {
try SecurityUtils.getKeyRefFromKeyChain(AppIDConstants.privateKeyIdentifier)
return true
} catch {
return false
}
}

internal func registerOAuthClient(callback :@escaping (Error?) -> Void) {
Expand Down Expand Up @@ -142,7 +150,6 @@ internal class RegistrationManager {
}
return registrationData[name] as? [String:Any]
}

public func getRegistrationDataArray(name:String) -> NSArray? {
guard let registrationData = self.getRegistrationData() else {
return nil
Expand Down
2 changes: 1 addition & 1 deletion Source/IBMCloudAppID/internal/SecurityUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal class SecurityUtils {
}
}

private static func getKeyRefFromKeyChain(_ tag:String) throws -> SecKey {
static func getKeyRefFromKeyChain(_ tag:String) throws -> SecKey {
let keyAttr : [NSString:AnyObject] = [
kSecClass : kSecClassKey,
kSecAttrApplicationTag: tag as AnyObject,
Expand Down

0 comments on commit c5567f6

Please sign in to comment.