Skip to content

Commit

Permalink
Development->master (#164)
Browse files Browse the repository at this point in the history
Add logging API
Add JP-tok region
  • Loading branch information
vitalymibm authored and gtaban committed Nov 27, 2018
1 parent 17be226 commit 81d6a93
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion IBMCloudAppID.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
1 change: 1 addition & 0 deletions Source/IBMCloudAppID/api/AppID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down
2 changes: 2 additions & 0 deletions Source/IBMCloudAppID/api/AppIDAuthorizationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -203,6 +204,7 @@ public class AppIDAuthorizationManager: BMSCore.AuthorizationManager {
Removes saved tokens
*/
public func logout() {
self.oAuthManager.tokenManager?.notifyLogout();
self.clearAuthorizationData()
}

Expand Down
41 changes: 41 additions & 0 deletions Source/IBMCloudAppID/internal/TokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 81d6a93

Please sign in to comment.