Commit 88a35155 authored by Jose Blaya's avatar Jose Blaya
Browse files

Remove the username and password from the Keychain

parent 1a3b4881
......@@ -249,6 +249,7 @@
84D5DA702126CE2900F753F8 /* QRCameraScannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D5DA6F2126CE2900F753F8 /* QRCameraScannerViewController.swift */; };
A6680249A33738280B9AD733 /* Pods_PIALibrary_PIALibraryHost_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 566B62D4C21DD5A90EF1BAE6 /* Pods_PIALibrary_PIALibraryHost_iOS.framework */; };
DD58F4BB21AEB99C00D043F7 /* GlossToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4BA21AEB99C00D043F7 /* GlossToken.swift */; };
DD58F4BD21AEF76100D043F7 /* String+Components.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4BC21AEF76100D043F7 /* String+Components.swift */; };
DDC812482176166600CB290C /* SwiftGen+ScenesStoryboards.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC812472176166500CB290C /* SwiftGen+ScenesStoryboards.swift */; };
DDC8124A217617F900CB290C /* SwiftGen+SeguesStoryboards.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC81249217617F900CB290C /* SwiftGen+SeguesStoryboards.swift */; };
/* End PBXBuildFile section */
......@@ -493,6 +494,7 @@
BB47885FCCA9DDFF53237D2C /* Pods-PIALibrary-PIALibraryTests-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PIALibrary-PIALibraryTests-iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-PIALibrary-PIALibraryTests-iOS/Pods-PIALibrary-PIALibraryTests-iOS.release.xcconfig"; sourceTree = "<group>"; };
D9FDC8980713EDCEDD51B936 /* Pods-PIALibrary-PIALibrary-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PIALibrary-PIALibrary-iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PIALibrary-PIALibrary-iOS/Pods-PIALibrary-PIALibrary-iOS.debug.xcconfig"; sourceTree = "<group>"; };
DD58F4BA21AEB99C00D043F7 /* GlossToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlossToken.swift; sourceTree = "<group>"; };
DD58F4BC21AEF76100D043F7 /* String+Components.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Components.swift"; sourceTree = "<group>"; };
DDC812472176166500CB290C /* SwiftGen+ScenesStoryboards.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SwiftGen+ScenesStoryboards.swift"; sourceTree = "<group>"; };
DDC81249217617F900CB290C /* SwiftGen+SeguesStoryboards.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SwiftGen+SeguesStoryboards.swift"; sourceTree = "<group>"; };
E526D8161FFFEE65AC2DF844 /* Pods-PIALibrary-PIALibraryTests-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PIALibrary-PIALibraryTests-iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PIALibrary-PIALibraryTests-iOS/Pods-PIALibrary-PIALibraryTests-iOS.debug.xcconfig"; sourceTree = "<group>"; };
......@@ -580,6 +582,7 @@
0E9D628B1FDEAC2D009A90CF /* module.modulemap */,
0E492C591FE5EA06007F23DF /* CMacros.h */,
0E492C5A1FE5EA06007F23DF /* CMacros.m */,
DD58F4BC21AEF76100D043F7 /* String+Components.swift */,
);
path = iOS;
sourceTree = "<group>";
......@@ -1556,6 +1559,7 @@
0EB8C0661F9CD38B005857E4 /* LoginViewController.swift in Sources */,
0EA8072C20A1C7A30033EC1A /* RedeemRequest.swift in Sources */,
0EC7A2A41F9D3D78006DDB91 /* RenewRequest.swift in Sources */,
DD58F4BD21AEF76100D043F7 /* String+Components.swift in Sources */,
0EE771091F9D21020029A77B /* Payment.swift in Sources */,
0E53A8531FE5D73F000C2A18 /* Client+Mock.swift in Sources */,
0E392D9D1FE31D630002160D /* MockVPNProvider.swift in Sources */,
......
......@@ -110,10 +110,16 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
callback?(nil, error)
return
}
self.accessedDatabase.plain.username = request.credentials.username
self.accessedDatabase.secure.setToken(token,
for: self.accessedDatabase.secure.tokenKey(for: request.credentials.username))
let tokenComponents = token.split(by: token.count/2)
if let first = tokenComponents.first,
let last = tokenComponents.last {
self.accessedDatabase.plain.username = first
self.accessedDatabase.secure.setToken(token,
for: self.accessedDatabase.secure.tokenKey(for: first))
self.accessedDatabase.secure.setPassword(last,
for: first)
}
self.webServices.info(token: token) { (accountInfo, error) in
guard let accountInfo = accountInfo else {
......@@ -122,8 +128,6 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
//Save after confirm the login was successful.
self.accessedDatabase.secure.setPassword(request.credentials.password,
for: request.credentials.username)
self.accessedDatabase.plain.accountInfo = accountInfo
let user = UserAccount(credentials: request.credentials, info: accountInfo)
......@@ -292,14 +296,34 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
callback?(nil, error)
return
}
self.accessedDatabase.plain.username = credentials.username
self.accessedDatabase.secure.setPassword(credentials.password, for: credentials.username)
let user = UserAccount(credentials: credentials, info: nil)
Macros.postNotification(.PIAAccountDidSignup, [
.user: user
])
callback?(user, nil)
self.webServices.token(credentials: credentials) { (token, error) in
guard let token = token else {
callback?(nil, error)
return
}
let tokenComponents = token.split(by: token.count/2)
if let first = tokenComponents.first,
let last = tokenComponents.last {
self.accessedDatabase.plain.username = first
self.accessedDatabase.secure.setToken(token,
for: self.accessedDatabase.secure.tokenKey(for: first))
self.accessedDatabase.secure.setPassword(last,
for: first)
}
let user = UserAccount(credentials: credentials, info: nil)
Macros.postNotification(.PIAAccountDidSignup, [
.user: user
])
callback?(user, nil)
}
}
}
......
//
// String+Components.swift
// PIALibrary-iOS
//
// Created by Jose Antonio Blaya Garcia on 28/11/2018.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import Foundation
extension String {
func split(by length: Int) -> [String] {
var startIndex = self.startIndex
var results = [Substring]()
while startIndex < self.endIndex {
let endIndex = self.index(startIndex, offsetBy: length, limitedBy: self.endIndex) ?? self.endIndex
results.append(self[startIndex..<endIndex])
startIndex = endIndex
}
return results.map { String($0) }
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment