Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2024-04-03 17:53:40 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c961b2aa2d72385baf31ba7c24043ef9813cdbe9
c961b2aa
1 parent
74b3c285
jwt changes logout
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
294 additions
and
9 deletions
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.h
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.m
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.h
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.h
View file @
c961b2a
...
...
@@ -50,7 +50,8 @@
-
(
NSMutableArray
*
)
getTagsCategories
;
-
(
NSMutableArray
*
)
getTags
;
-
(
NSDictionary
*
)
login
:(
NSString
*
)
id
password
:(
NSString
*
)
password
loginType
:(
NSString
*
)
loginType
;
-
(
NSDictionary
*
)
logout
;
// - (NSDictionary *)logout;
-
(
void
)
logout
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
NSDictionary
*
)
register
:(
NSString
*
)
id
password
:(
NSString
*
)
password
name
:(
NSString
*
)
name
email
:(
NSString
*
)
email
segmentation
:(
NSNumber
*
)
segmentation
newsletter
:(
NSNumber
*
)
newsletter
;
-
(
NSDictionary
*
)
registerAutoLogin
:(
NSString
*
)
id
password
:(
NSString
*
)
password
name
:(
NSString
*
)
name
email
:(
NSString
*
)
email
segmentation
:(
NSNumber
*
)
segmentation
newsletter
:(
NSNumber
*
)
newsletter
loginType
:(
NSString
*
)
loginType
;
-
(
NSDictionary
*
)
refreshToken
;
...
...
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.m
View file @
c961b2a
...
...
@@ -638,10 +638,23 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
return
resp
;
}
-
(
NSDictionary
*
)
logout
{
NSDictionary
*
response
=
[
NSDictionary
alloc
];
response
=
[[
Warply
sharedService
]
logout
];
return
response
;
// - (NSDictionary *)logout {
// NSDictionary *response = [NSDictionary alloc];
// response = [[Warply sharedService] logout];
// return response;
// }
-
(
void
)
logout
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
[[
Warply
sharedService
]
logout
:
^
(
NSDictionary
*
response
)
{
if
(
success
)
{
success
(
response
);
}
}
failureBlock
:
^
(
NSError
*
error
)
{
if
(
failure
)
{
failure
(
error
);
}
}];
}
-
(
NSDictionary
*
)
register
:
(
NSString
*
)
id
password
:
(
NSString
*
)
password
name
:
(
NSString
*
)
name
email
:
(
NSString
*
)
email
segmentation
:
(
NSNumber
*
)
segmentation
newsletter
:
(
NSNumber
*
)
newsletter
{
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.h
View file @
c961b2a
...
...
@@ -325,7 +325,9 @@ WL_VERSION_INTERFACE()
-
(
void
)
loginWithSuccessBlock
:(
NSString
*
)
id
andPassword
:(
NSString
*
)
password
andLoginType
:(
NSString
*
)
loginType
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
NSDictionary
*
)
logout
;
// - (NSDictionary*)logout;
-
(
void
)
logout
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
webAuthorizeWithSuccessBlock
:(
NSDictionary
*
)
contextResponse
andId
:(
NSString
*
)
id
andLoginType
:(
NSString
*
)
loginType
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
;
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
View file @
c961b2a
...
...
@@ -1159,15 +1159,85 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
-
(
NSDictionary
*
)
logout
// - (NSDictionary*)logout
// {
// @synchronized (_DatabaseLock) {
// [_db executeUpdate:@"DROP TABLE requestVariables"];
// }
// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
// NSLog(@"**************** WARPLY Logout *****************" );
// return successResponse;
// }
-
(
void
)
logout
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
/*
POST https://engage-stage.warp.ly/oauth/<app_uuid>/logout
{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMyMjI4ODYsImlhdCI6MTcxMDE2ODIwMiwiZXhwIjoxNzEwMTcwMDAyLCJIT1NUIjoiaHR0cHM6Ly9lbmdhZ2Utc3RhZ2Uud2FycC5seSJ9.8W9x4uuEsZiL8NNtJmpA1I3JsMtx8j3jePAnGekNkAM",
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMyMjI4ODYsImlhdCI6MTcxMDE2ODIwMiwiZXhwIjoxNzEwMTcwMDAyLCJIT1NUIjoiaHR0cHM6Ly9lbmdhZ2Utc3RhZ2Uud2FycC5seSJ9.8W9x4uuEsZiL8NNtJmpA1I3JsMtx8j3jePAnGekNkAM"}
*/
BOOL
tableExist
=
NO
;
@try
{
@synchronized
(
_DatabaseLock
)
{
tableExist
=
[
_db
tableExists
:
@"requestVariables"
];
}
}
@catch
(
NSException
*
exception
)
{
NSLog
(
@"tableExists error: %@"
,
exception
.
reason
);
if
(
failure
)
{
NSError
*
error
=
nil
;
failure
(
error
);
}
}
@finally
{
// NSLog(@"Finally condition");
}
if
(
tableExist
==
YES
)
{
NSString
*
accessToken
=
@""
;
NSString
*
refreshToken
=
@""
;
accessToken
=
[
_sharedService
getAccessToken2
];
refreshToken
=
[
_sharedService
getRefreshToken
];
NSMutableDictionary
*
data
=
[[
NSMutableDictionary
alloc
]
init
];
[
data
setValue
:
accessToken
forKey
:
@"access_token"
];
[
data
setValue
:
refreshToken
forKey
:
@"refresh_token"
];
NSData
*
jsonData
=
[
NSJSONSerialization
dataWithJSONObject
:
data
options
:
0
error
:
NULL
];
[
self
sendContextLogout
:
jsonData
successBlock
:
^
(
NSDictionary
*
contextResponse
)
{
if
(
success
)
{
// success(contextResponse);
@synchronized
(
_DatabaseLock
)
{
[
_db
executeUpdate
:
@"DROP TABLE requestVariables"
];
}
NSDictionary
*
successResponse
=
@{
@"result"
:
@"success"
,
@"status"
:
@1
};
NSLog
(
@"**************** WARPLY Logout *****************"
);
return
successResponse
;
success
(
successResponse
);
}
NSLog
(
@"**************** WARPLY Response *****************"
);
NSLog
(
@"%@"
,
contextResponse
);
}
failureBlock
:^
(
NSError
*
error
)
{
if
(
failure
)
{
failure
(
error
);
// NSDictionary *failureResponse = @{@"result": @"failure", @"status":@2};
// failure(failureResponse);
}
NSLog
(
@"Error at logout %@"
,
error
);
}];
}
// @synchronized (_DatabaseLock) {
// [_db executeUpdate:@"DROP TABLE requestVariables"];
// }
// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
// NSLog(@"**************** WARPLY Logout *****************" );
// return successResponse;
}
-
(
void
)
webAuthorizeWithSuccessBlock
:
(
NSDictionary
*
)
contextResponse
andId
:
(
NSString
*
)
id
andLoginType
:
(
NSString
*
)
loginType
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
...
...
@@ -4606,6 +4676,35 @@ NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithInvoca
return
appIsRegisteredWithWarply
;
}
-
(
BOOL
)
sendContextLogout
:
(
NSData
*
)
context
successBlock
:
(
void
(
^
)(
NSDictionary
*
contextResponse
))
successBlock
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failureBlock
{
BOOL
appIsRegisteredWithWarply
=
[
self
isRegistrationValid
];
if
(
WL_FEATURE_IS_DISABLED_WITH_KEY
(
WL_WARPLY_ENABLED
))
return
appIsRegisteredWithWarply
;
if
(
appIsRegisteredWithWarply
==
NO
)
{
[
_pendingOperationsQueue
setSuspended
:
YES
];
[
self
registration
];
}
NSString
*
path
=
nil
;
// NSString *path = @"logout";
NSInvocation
*
invocation
=
[
self
contextRequestInvocationWithTypeLogout
:
WLContextRequestTypePost
data
:
context
path
:
path
successBlock
:
[
successBlock
copy
]
failureBlock
:
[
failureBlock
copy
]];
NSInvocationOperation
*
operation
=
[[
NSInvocationOperation
alloc
]
initWithInvocation
:
invocation
];
[
_pendingOperationsQueue
addOperation
:
operation
];
return
appIsRegisteredWithWarply
;
}
#pragma - Events
///////////////////////////////////////////////////////////////////////////////
-
(
void
)
addEvent
:
(
WLEvent
*
)
event
priority
:
(
BOOL
)
priority
...
...
@@ -6287,6 +6386,28 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
return
invocation
;
}
-
(
NSInvocation
*
)
contextRequestInvocationWithTypeLogout
:
(
WLContextRequestType
)
type
data
:
(
NSData
*
)
context
path
:
(
NSString
*
)
path
successBlock
:
(
void
(
^
)(
NSDictionary
*
contextResponse
))
successBlock
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failureBlock
{
void
(
^
successBlockCopy
)(
void
)
=
[
successBlock
copy
];
void
(
^
failureBlockCopy
)(
void
)
=
[
failureBlock
copy
];
NSMethodSignature
*
sgn
=
[
self
methodSignatureForSelector
:
@selector
(
runContextRequestWithTypeLogout
:
data
:
path
:
successBlock
:
failureBlock
:
)];
NSInvocation
*
invocation
=
[
NSInvocation
invocationWithMethodSignature
:
sgn
];
[
invocation
setTarget
:
self
];
[
invocation
setSelector
:
@selector
(
runContextRequestWithTypeLogout
:
data
:
path
:
successBlock
:
failureBlock
:
)];
[
invocation
setArgument
:
&
type
atIndex
:
2
];
[
invocation
setArgument
:
&
context
atIndex
:
3
];
[
invocation
setArgument
:
&
path
atIndex
:
4
];
[
invocation
setArgument
:
&
successBlockCopy
atIndex
:
5
];
[
invocation
setArgument
:
&
failureBlockCopy
atIndex
:
6
];
[
invocation
retainArguments
];
return
invocation
;
}
-
(
NSInvocation
*
)
contextRequestInvocationWithTypeCampaign
:
(
WLContextRequestType
)
type
data
:
(
NSData
*
)
context
path
:
(
NSString
*
)
path
...
...
@@ -6597,6 +6718,10 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
urlString
=
[
NSMutableString
stringWithFormat
:
@"%@/api/async/info/%@/"
,
_baseURL
,
_appUUID
];
}
// if([path isEqualToString:@"logout"]){
// urlString = [NSMutableString stringWithFormat:@"%@/oauth/%@/logout", _baseURL, _appUUID];
// }
WLLOG
(
@"[WARP Trace] HTTP URL: %@"
,
urlString
);
NSMutableURLRequest
*
request
=
[
NSMutableURLRequest
requestWithURL
:[
NSURL
URLWithString
:
urlString
]
cachePolicy
:
NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval
:
30
.
0
];
...
...
@@ -6717,6 +6842,94 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
}
}
-
(
void
)
runContextRequestWithTypeLogout
:
(
WLContextRequestType
)
requestType
data
:
(
NSData
*
)
context
path
:
(
NSString
*
)
path
successBlock
:
(
void
(
^
)(
id
contextResponse
))
successBlock
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failureBlock
{
//Create REQUEST
// POST https://engage-stage.warp.ly/oauth/<app_uuid>/logout
NSMutableString
*
urlString
=
[
NSMutableString
stringWithFormat
:
@"%@/oauth/%@/logout"
,
_baseURL
,
_appUUID
];
WLLOG
(
@"[WARP Trace] HTTP URL: %@"
,
urlString
);
NSMutableURLRequest
*
request
=
[
NSMutableURLRequest
requestWithURL
:[
NSURL
URLWithString
:
urlString
]
cachePolicy
:
NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval
:
30
.
0
];
[
request
setTimeoutInterval
:
30
.
0
];
NSDictionary
*
parameters
;
if
(
context
!=
nil
)
{
parameters
=
[
NSJSONSerialization
JSONObjectWithData
:
context
options
:
NSJSONReadingAllowFragments
error
:
NULL
];
}
SuccessResponse
successResponse
=
^
(
NSURLSessionDataTask
*
_Nonnull
task
,
id
_Nullable
JSON
)
{
if
(
JSON
==
nil
)
{
successBlock
(@{
@"status"
:
@"0"
});
}
else
{
// NSData *responseData = [NSJSONSerialization dataWithJSONObject:JSON options:NSJSONWritingPrettyPrinted error:NULL];
// NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// WLLOG(@"[WARP Trace] HTTP %@ Response:%@", request.HTTPMethod, responseString);
WLLOG
(
@"************ WARP %@ CONTEXT ******************"
,
request
.
HTTPMethod
);
WLLOG
(
@"[WARP Trace] HTTP Web Id: %@"
,
_webId
);
WLLOG
(
@"[WARP Trace] HTTP API Key: %@"
,
_apiKey
);
WLLOG
(
@"[WARP Trace] HTTP %@ Request URL: %@"
,
request
.
HTTPMethod
,
request
.
URL
.
absoluteString
);
NSString
*
contextString
=
[[
NSString
alloc
]
initWithData
:
context
encoding
:
NSUTF8StringEncoding
];
WLLOG
(
@"[WARP Trace] HTTP %@ Request Body: %@"
,
request
.
HTTPMethod
,
contextString
);
WLLOG
(
@"*************************************************"
);
if
(
successBlock
)
{
successBlock
(
JSON
);
}
}
};
FailureResponse
faliureResponse
=
^
(
NSURLSessionDataTask
*
_Nullable
task
,
NSError
*
_Nonnull
error
)
{
WLLOG
(
@"************ WARP %@ CONTEXT ******************"
,
request
.
HTTPMethod
);
WLLOG
(
@"[WARP Trace] HTTP Web Id: %@"
,
_webId
);
WLLOG
(
@"[WARP Trace] HTTP API Key: %@"
,
_apiKey
);
WLLOG
(
@"[WARP Trace] HTTP %@ Request URL: %@"
,
request
.
HTTPMethod
,
request
.
URL
.
absoluteString
);
NSString
*
contextString
=
[[
NSString
alloc
]
initWithData
:
context
encoding
:
NSUTF8StringEncoding
];
WLLOG
(
@"[WARP Trace] HTTP %@ Request Body: %@"
,
request
.
HTTPMethod
,
contextString
);
WLLOG
(
@"[WARP Trace] Error: %@"
,
[
error
description
]);
WLLOG
(
@"*************************************************"
);
if
(
failureBlock
)
failureBlock
(
error
);
};
_httpClient
.
responseSerializer
=
[
AFJSONResponseSerializer
serializer
];
_httpClient
.
requestSerializer
=
[
AFJSONRequestSerializer
serializer
];
[
_httpClient
.
requestSerializer
setTimeoutInterval
:
30
];
//Set HTTP Headers
time_t
timestamp
=
(
time_t
)
[[
NSDate
date
]
timeIntervalSince1970
];
[
_httpClient
.
requestSerializer
setValue
:
_webId
forHTTPHeaderField
:
@"loyalty-web-id"
];
[
_httpClient
.
requestSerializer
setValue
:[
NSString
stringWithFormat
:
@"%lu"
,
timestamp
]
forHTTPHeaderField
:
@"loyalty-date"
];
[
_httpClient
.
requestSerializer
setValue
:[[
NSString
stringWithFormat
:
@"%@%lu"
,
_apiKey
,
timestamp
]
SHA256Sum
]
forHTTPHeaderField
:
@"loyalty-signature"
];
[
_httpClient
.
requestSerializer
setValue
:
@"gzip"
forHTTPHeaderField
:
@"Accept-Encoding"
];
[
_httpClient
.
requestSerializer
setValue
:
@"application/json"
forHTTPHeaderField
:
@"Accept"
];
[
_httpClient
.
requestSerializer
setValue
:
@"gzip"
forHTTPHeaderField
:
@"User-Agent"
];
[
_httpClient
.
requestSerializer
setValue
:[
NSString
stringWithFormat
:
@"ios:%@"
,
[[
NSBundle
mainBundle
]
objectForInfoDictionaryKey
:
@"CFBundleIdentifier"
]]
forHTTPHeaderField
:
@"loyalty-bundle-id"
];
[
_httpClient
.
requestSerializer
setValue
:[[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
]
forHTTPHeaderField
:
@"unique-device-id"
];
[
_httpClient
.
requestSerializer
setValue
:
@"apple"
forHTTPHeaderField
:
@"vendor"
];
[
_httpClient
.
requestSerializer
setValue
:
@"platform"
forHTTPHeaderField
:
@"ios"
];
[
_httpClient
.
requestSerializer
setValue
:
@"os_version"
forHTTPHeaderField
:[[
UIDevice
currentDevice
]
systemVersion
]];
[
_httpClient
.
requestSerializer
setValue
:
@"mobile"
forHTTPHeaderField
:
@"channel"
];
if
(
requestType
==
WLContextRequestTypePost
)
{
// NSDictionary *parameters = [NSJSONSerialization JSONObjectWithData:context options:NSJSONReadingAllowFragments error:NULL];
[
_httpClient
POST
:
urlString
parameters
:
parameters
progress
:
nil
success
:
successResponse
failure
:
faliureResponse
];
}
else
{
[
_httpClient
GET
:
urlString
parameters
:
parameters
progress
:
nil
success
:
successResponse
failure
:
faliureResponse
];
}
}
-
(
void
)
runContextRequestWithTypeCampaign
:
(
WLContextRequestType
)
requestType
data
:
(
NSData
*
)
context
path
:
(
NSString
*
)
path
...
...
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
View file @
c961b2a
...
...
@@ -7590,10 +7590,55 @@ public class swiftApi {
}
// public func logout(_ logoutCallback: @escaping (_ responseData: VerifyTicketResponseModel?) -> Void) -> Void {
// let instanceOfMyApi = MyApi()
// let responseData = instanceOfMyApi.logout() as [AnyHashable: Any]?
// if let responseDataDictionary = responseData as? [String: Any] {
// let tempResponse = VerifyTicketResponseModel(dictionary: responseDataDictionary)
// if (tempResponse.getStatus == 1) {
// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
// dynatraceEvent._eventName = "custom_success_logout_loyalty"
// dynatraceEvent._parameters = nil
// SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
// swiftApi().setUserTag("")
// swiftApi().setUserNonTelco(false)
// swiftApi().setCCMSLoyaltyCampaigns(campaigns: [])
// let accessToken = instanceOfMyApi.getAccessTokenM()
// print("=================== TOKEN DELETED =========================")
// print("Bearer: ", accessToken)
// print("=================== TOKEN DELETED =========================")
// } else {
// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
// dynatraceEvent._eventName = "custom_error_logout_loyalty"
// dynatraceEvent._parameters = nil
// SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
// }
// logoutCallback(tempResponse);
// } else {
// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
// dynatraceEvent._eventName = "custom_error_logout_loyalty"
// dynatraceEvent._parameters = nil
// SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
// logoutCallback(nil)
// }
// }
public
func
logout
(
_
logoutCallback
:
@escaping
(
_
responseData
:
VerifyTicketResponseModel
?)
->
Void
)
->
Void
{
let
instanceOfMyApi
=
MyApi
()
let
responseData
=
instanceOfMyApi
.
logout
()
as
[
AnyHashable
:
Any
]?
instanceOfMyApi
.
logout
(
successCallback
,
failureBlock
:
failureCallback
)
func
successCallback
(
_
responseData
:
[
AnyHashable
:
Any
]?)
->
Void
{
if
let
responseDataDictionary
=
responseData
as?
[
String
:
Any
]
{
...
...
@@ -7633,6 +7678,17 @@ public class swiftApi {
}
}
func
failureCallback
(
_
error
:
Error
?)
->
Void
{
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_logout_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
logoutCallback
(
nil
)
}
}
public
func
didReceiveNotification
(
_
payload
:
[
String
:
Any
])
->
Void
{
...
...
Please
register
or
login
to post a comment