diff --git a/AgileWorks/AgileWorks.xcodeproj/project.pbxproj b/AgileWorks/AgileWorks.xcodeproj/project.pbxproj index bafadefc015576e1f17c2287f7dc2f183af71c28..1d97a0dda69ce89aa871648e7230ec5125d4379c 100644 --- a/AgileWorks/AgileWorks.xcodeproj/project.pbxproj +++ b/AgileWorks/AgileWorks.xcodeproj/project.pbxproj @@ -151,6 +151,7 @@ C535772E2754D5C500EAA660 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C535772D2754D5C500EAA660 /* WebViewController.swift */; }; C53577372758AC1100EAA660 /* WebViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C53577362758AC1100EAA660 /* WebViewController.storyboard */; }; C5377F0327E07CD9004467BE /* MainTabBarViewWireframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5377F0227E07CD9004467BE /* MainTabBarViewWireframe.swift */; }; + C56E32FD27F2EDC1003455B5 /* GetLogoutEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = C56E32FC27F2EDC1003455B5 /* GetLogoutEndpoint.swift */; }; C57DCAAA27C89692000A2ABC /* ProfileViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C57DCAA927C89692000A2ABC /* ProfileViewController.storyboard */; }; C57DCAAE27C89823000A2ABC /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C57DCAAD27C89823000A2ABC /* ProfileViewController.swift */; }; C57DCAB027C8AEFC000A2ABC /* ProfileTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C57DCAAF27C8AEFC000A2ABC /* ProfileTableViewController.swift */; }; @@ -336,6 +337,7 @@ C535772D2754D5C500EAA660 /* WebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = ""; }; C53577362758AC1100EAA660 /* WebViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = WebViewController.storyboard; sourceTree = ""; }; C5377F0227E07CD9004467BE /* MainTabBarViewWireframe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarViewWireframe.swift; sourceTree = ""; }; + C56E32FC27F2EDC1003455B5 /* GetLogoutEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetLogoutEndpoint.swift; sourceTree = ""; }; C57DCAA927C89692000A2ABC /* ProfileViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = ProfileViewController.storyboard; sourceTree = ""; }; C57DCAAD27C89823000A2ABC /* ProfileViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewController.swift; sourceTree = ""; }; C57DCAAF27C8AEFC000A2ABC /* ProfileTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileTableViewController.swift; sourceTree = ""; }; @@ -833,6 +835,7 @@ 76CEA0572511D1930074837A /* PostWfActionEndpoint.swift */, 76D1DC1D2592FE3400429C70 /* GetDocumentInfoEndpoint.swift */, 76D1C0DE25E38D0A004DF611 /* GetServiceInfoEndpoint.swift */, + C56E32FC27F2EDC1003455B5 /* GetLogoutEndpoint.swift */, ); path = WebClient; sourceTree = ""; @@ -1381,6 +1384,7 @@ 76AE52DD25D35CDC00AFA45A /* LicenseUtility.swift in Sources */, BDAB1F6F240D0D1400EA15FD /* APIEndpoint.swift in Sources */, C50CF79227D8708B0042C210 /* OpenLicenseViewController.swift in Sources */, + C56E32FD27F2EDC1003455B5 /* GetLogoutEndpoint.swift in Sources */, 761F4A49255D15DA007708D8 /* AppShared.swift in Sources */, BD6C1AEA24A4775C0057756F /* UIDeviceExtensions.swift in Sources */, BD72589F240E69E000928CE9 /* OAuthService.swift in Sources */, diff --git a/AgileWorks/AgileWorks/App/RootViewController.swift b/AgileWorks/AgileWorks/App/RootViewController.swift index 578203f73f2ea82d840018a7a3ffd36f376cb62d..774c23d369ec88215dc5df2a0b393c83505b47c9 100644 --- a/AgileWorks/AgileWorks/App/RootViewController.swift +++ b/AgileWorks/AgileWorks/App/RootViewController.swift @@ -56,7 +56,7 @@ extension RootViewController { // ログアウトアラート デフォルトボタンアクション生成 func logoutDefaultAction(title: String) -> UIAlertAction { let defaultAction = UIAlertAction(title: title, style: .default) { _ in - DeviceService().deleteDevice { result in + self.logout { result in switch result { case .success: break @@ -65,6 +65,7 @@ extension RootViewController { } KeychainDataStore().removeOAuthState() KeychainDataStore().removeAccessToken() + KeychainDataStore().removeSessionID() KeychainDataStore().removeDeviceID() DispatchQueue.main.async { @@ -164,4 +165,20 @@ extension RootViewController { completion?() }) } + + // ログアウト処理 + private func logout(completion: @escaping(APIResult) -> Void) { + let logout = GetLogoutEndpoint() + Session.send(logout) { result in + let completionArg: APIResult + switch result { + case .success: + completionArg = .success(true) + case .failure(let error): + log.e(error) + completionArg = .failure(error) + } + completion(completionArg) + } + } } diff --git a/AgileWorks/AgileWorks/WebView/View/MenuViewController.swift b/AgileWorks/AgileWorks/WebView/View/MenuViewController.swift index 7e1cdccb1f7c832b45a68ce25ab79a4125c9ec9c..00b73b52da12d360166089e0f80878c32f11b516 100644 --- a/AgileWorks/AgileWorks/WebView/View/MenuViewController.swift +++ b/AgileWorks/AgileWorks/WebView/View/MenuViewController.swift @@ -60,8 +60,10 @@ class MenuViewController: UIViewController { switch result { case .success(let response): let userName = response.user.name + let sessionId = response.sessionId DispatchQueue.main.async { self.nameLabel.text = userName + KeychainDataStore().writeSessionID(sessionID: sessionId) } case .failure: DispatchQueue.main.async { diff --git a/AgileWorks/Common/DataStore/KeychainDataStore.swift b/AgileWorks/Common/DataStore/KeychainDataStore.swift index bea972d64adddc7c196fb7f27ca67520d97e4938..681a27c146c33e8e13104f779fb020c1ba38129b 100644 --- a/AgileWorks/Common/DataStore/KeychainDataStore.swift +++ b/AgileWorks/Common/DataStore/KeychainDataStore.swift @@ -19,6 +19,7 @@ final class KeychainDataStore: DataStoreProtocol { private let kServerURL: String = "ServerURL" private let kContextPath: String = "ContextPath" private let kDeviceID: String = "DeviceID" + private let kSessionID: String = "SessionID" // アクセストークンの書き込み func writeAccessToken(accessToken: String) { @@ -127,6 +128,21 @@ final class KeychainDataStore: DataStoreProtocol { removeKeychainValue(key: kDeviceID) } + // セッションIDの書き込み + func writeSessionID(sessionID: String) { + setKeychainValue(key: kSessionID, value: sessionID) + } + + // セッションIDの読み込み + func readSessionID() -> String? { + return getKeychainValue(key: kSessionID) + } + + // セッションIDの削除 + func removeSessionID() { + removeKeychainValue(key: kSessionID) + } + // KeyChain へ指定の値をセット private func setKeychainValue(key: String, value: String) { let keychain = Keychain(service: service, accessGroup: groupId) diff --git a/AgileWorks/Common/WebClient/APIEndpoint.swift b/AgileWorks/Common/WebClient/APIEndpoint.swift index 3ebc98d3d2534630ffedd0ae49af736c653f1a5a..1ef653cf71860ff5907699dd5c779695b42ffa8d 100644 --- a/AgileWorks/Common/WebClient/APIEndpoint.swift +++ b/AgileWorks/Common/WebClient/APIEndpoint.swift @@ -24,6 +24,7 @@ public protocol APIEndpoint { var method: HttpMethod { get } var path: String { get } var headerFields: [String: String]? { get } + var cookieFields: [String: String]? { get } var pathParameters: [String]? { get } var queryParameters: [String: String]? { get } @@ -45,6 +46,10 @@ public extension APIEndpoint { return nil } + var cookieFields: [String: String]? { + return nil + } + var pathParameters: [String]? { return nil } @@ -71,6 +76,11 @@ public extension APIEndpoint { req.httpBody = requestBody req.httpShouldHandleCookies = false + // cookies の設定 + for(key, value) in cookieFields ?? [:] { + req.setValue(key + "=" + value, forHTTPHeaderField: "Cookie") + req.httpShouldHandleCookies = true + } return req } diff --git a/AgileWorks/Common/WebClient/GetLogoutEndpoint.swift b/AgileWorks/Common/WebClient/GetLogoutEndpoint.swift new file mode 100644 index 0000000000000000000000000000000000000000..d39aad59f004193fa88e8e56fb8a761fd9a5ba0b --- /dev/null +++ b/AgileWorks/Common/WebClient/GetLogoutEndpoint.swift @@ -0,0 +1,33 @@ +// +// GetLogoutEndpoint.swift +// AgileWorks +// +// Created by Gk40002148 on 2022/03/29. +// Copyright © 2022 ATLED CORP. All rights reserved. +// + +import Foundation + +struct GetLogoutEndpoint: APIEndpoint { + var requestBody: Data? + + typealias Response = Bool + + let method: HttpMethod = .GET + let path = "/" + (KeychainDataStore().readContextPath() ?? "") + "/Broker/MobileAppApi/Logout" + + var headerFields: [String: String]? { + return ["Authorization": "Bearer \(KeychainDataStore().readAccessToken() ?? "")", + "X-ATLED-AW-Device-Id": KeychainDataStore().readDeviceID()?.description ?? ""] + } + + var cookieFields: [String: String]? { + return ["JSESSIONID": KeychainDataStore().readSessionID() ?? ""] + } +} + +extension GetLogoutEndpoint { + func response(from object: Any, urlResponse: HTTPURLResponse) throws -> Response { + return true + } +}