diff --git a/IBMCloudAppID.podspec b/IBMCloudAppID.podspec index 4364a5b..9f4c8c7 100755 --- a/IBMCloudAppID.podspec +++ b/IBMCloudAppID.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "IBMCloudAppID" - s.version = '4.1.0' + s.version = '4.2.0' s.summary = "AppID Swift SDK" s.homepage = "https://github.com/ibm-cloud-security/appid-clientsdk-swift" s.license = 'Apache License, Version 2.0' diff --git a/Source/IBMCloudAppID/api/AppID.swift b/Source/IBMCloudAppID/api/AppID.swift index 988bbbd..ddb6729 100644 --- a/Source/IBMCloudAppID/api/AppID.swift +++ b/Source/IBMCloudAppID/api/AppID.swift @@ -33,6 +33,7 @@ public class AppID { static public let REGION_UK = ".eu-gb.bluemix.net" static public let REGION_SYDNEY = ".au-syd.bluemix.net" static public let REGION_GERMANY = ".eu-de.bluemix.net" + static public let REGION_TOKYO = ".jp-tok.bluemix.net" internal init() {} diff --git a/Source/IBMCloudAppID/api/AppIDAuthorizationManager.swift b/Source/IBMCloudAppID/api/AppIDAuthorizationManager.swift index 5ec01c5..88d45ca 100644 --- a/Source/IBMCloudAppID/api/AppIDAuthorizationManager.swift +++ b/Source/IBMCloudAppID/api/AppIDAuthorizationManager.swift @@ -121,6 +121,7 @@ public class AppIDAuthorizationManager: BMSCore.AuthorizationManager { public func clearAuthorizationData() { AppIDAuthorizationManager.logger.debug(message: "clearAuthorizationData") + self.oAuthManager.tokenManager?.notifyLogout(); self.oAuthManager.tokenManager?.clearStoredToken() } @@ -203,6 +204,7 @@ public class AppIDAuthorizationManager: BMSCore.AuthorizationManager { Removes saved tokens */ public func logout() { + self.oAuthManager.tokenManager?.notifyLogout(); self.clearAuthorizationData() } diff --git a/Source/IBMCloudAppID/internal/TokenManager.swift b/Source/IBMCloudAppID/internal/TokenManager.swift index 1c61b0d..def053a 100644 --- a/Source/IBMCloudAppID/internal/TokenManager.swift +++ b/Source/IBMCloudAppID/internal/TokenManager.swift @@ -297,5 +297,46 @@ internal class TokenManager { self.latestIdentityToken = nil self.latestRefreshToken = nil } + internal func sendLoggingRequest(accessToken:AccessToken?, idToken:IdentityToken?, eventName:String) { + if (accessToken == nil || idToken == nil) { + TokenManager.logger.debug(message: "No tokens found for sending logging request"); + return; + } + + let loggingUrl = Config.getServerUrl(appId: self.appid) + "/activity_logging" + let headers : [String: String] = [ + "Authorization" : "Bearer " + accessToken!.raw, + "Content-Type" : "application/json" + ] + let jsonObject: [String: String] = [ + "eventName" : eventName, + "id_token" : idToken!.raw + ] + var body : Data + do { + body = try JSONSerialization.data(withJSONObject: jsonObject) + } catch { + TokenManager.logger.debug(message:"JSON error while creating logging request") + return; + } + + let internalCallback: BMSCompletionHandler = {(response: Response?, error: Error?) in + if error != nil { + TokenManager.logger.error(message: "Error sending logging request"); + } else { + TokenManager.logger.debug(message: "OK sending logging request"); + } + } + + let request = Request(url: loggingUrl, method: HttpMethod.POST, headers: headers, queryParameters: nil, timeout: 0) + request.timeout = BMSClient.sharedInstance.requestTimeout + + // body.data(using: .utf8)*/ + sendRequest(request: request, body: body, internalCallBack: internalCallback) + } + public func notifyLogout() { + + sendLoggingRequest(accessToken:self.latestAccessToken, idToken:self.latestIdentityToken, eventName:"logout"); + } }