NETWORK_TESTING_AUTHORIZATION.md
5.09 KB
Network Testing - Authorization Fix
Issue Summary
The getCosmoteUser
endpoint was failing with a 405 Method Not Allowed error during testing.
Root Cause Analysis
After examining the original Objective-C implementation in /Users/manos/Desktop/warply_projects/warply_sdk/warply_sdk_framework/SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
, I found that:
Original Implementation (Objective-C) - CORRECT ✅
- (void)getCosmoteUserWithSuccessBlock:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSMutableDictionary* postDictionary = [[NSMutableDictionary alloc] init];
[postDictionary setValue:guid forKey:@"user_identifier"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL];
[self sendContextGetCosmoteUser:jsonData successBlock:^(NSDictionary *contextResponse) {
// ... success handling
} failureBlock:^(NSError *error) {
// ... error handling
}];
}
And in the request implementation:
- (void)getCosmoteUserRequestWithType:(WLContextRequestType)requestType
{
NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@/partners/oauth/%@/token", _baseURL, _appUUID];
// ...
[_httpClient.requestSerializer setValue:[@"Basic " stringByAppendingString:@"MVBQNFhCQzhFYTJBaUdCNkJWZGFGUERlTTNLQ3kzMjU6YzViMzAyZDY5N2FiNGY3NzhiNThhMTg0YzBkZWRmNGU="] forHTTPHeaderField:@"Authorization"];
// ...
if (requestType == WLContextRequestTypePost) {
[_httpClient POST:urlString parameters:parameters progress:nil success:successResponse failure:faliureResponse];
}
}
Key Points:
- Uses POST method with JSON body
- Sends
user_identifier
in request body, not as query parameter - Uses Basic Authentication with hardcoded credentials
Swift Implementation (WRONG) - BEFORE FIX ❌
case .getCosmoteUser:
return .GET // ❌ This was wrong!
The Swift framework was using GET method, but the server expects POST.
Fix Applied ✅
1. Fixed HTTP Method in Endpoints.swift
File: SwiftWarplyFramework/SwiftWarplyFramework/Network/Endpoints.swift
Before:
case .getSingleCampaign, .getCosmoteUser, .getNetworkStatus:
return .GET
After:
case .register, .changePassword, .resetPassword, .requestOtp, .verifyTicket, .refreshToken, .logout, .getCampaigns, .getCampaignsPersonalized,
.getCoupons, .getCouponSets, .getAvailableCoupons,
.getMarketPassDetails, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon, .getMerchants, .sendEvent, .sendDeviceInfo, .getCosmoteUser:
return .POST
case .getSingleCampaign, .getNetworkStatus:
return .GET
2. Verified NetworkService Configuration
The NetworkService was already correctly configured:
Basic Authentication: ✅ Already implemented
private func addBasicAuthHeaders(to request: inout URLRequest, endpoint: Endpoint) {
if endpoint.path.contains("/partners/cosmote/") || endpoint.path.contains("/partners/oauth/") {
let basicAuth = "MVBQNFhCQzhFYTJBaUdCNkJWZGFGUERlTTNLQ3kzMjU6YzViMzAyZDY5N2FiNGY3NzhiNThhMTg0YzBkZWRmNGU="
request.setValue("Basic \(basicAuth)", forHTTPHeaderField: "Authorization")
print("🔐 [NetworkService] Added Basic authentication for Cosmote endpoint")
}
}
Request Body: ✅ Already implemented
case .getCosmoteUser(let guid):
return [
"user_identifier": guid
]
Authentication Type: ✅ Already implemented
case .getCosmoteUser:
return .basicAuth
Expected Result
After this fix, the getCosmoteUser
endpoint should:
- ✅ Use POST method instead of GET
- ✅ Send
user_identifier
in JSON request body - ✅ Include Basic Authentication header
- ✅ Receive successful response from server
Test Logs Analysis
Before Fix (ERROR):
📤 [NetworkService] REQUEST
🔗 URL: https://engage-stage.warp.ly/partners/oauth/f83dfde1145e4c2da69793abb2f579af/token?user_identifier=7000000833
🔧 Method: GET ← WRONG METHOD
📦 Body: (No body) ← MISSING BODY
📥 [NetworkService] RESPONSE
❌ Status: 405
allow: OPTIONS, POST ← SERVER EXPECTS POST
After Fix (EXPECTED):
📤 [NetworkService] REQUEST
🔗 URL: https://engage-stage.warp.ly/partners/oauth/f83dfde1145e4c2da69793abb2f579af/token
🔧 Method: POST ← CORRECT METHOD
📋 Headers:
Authorization: Basi***NGU= ← BASIC AUTH PRESENT
📦 Body Content: {"user_identifier":"7000000833"} ← CORRECT BODY
📥 [NetworkService] RESPONSE
✅ Status: 200 ← SUCCESS EXPECTED
Next Steps
- Test the
getCosmoteUser
endpoint again - Verify that it now returns a successful response
- Continue with the authorization testing checklist
Files Modified
-
SwiftWarplyFramework/SwiftWarplyFramework/Network/Endpoints.swift
- Fixed HTTP method from GET to POST
Files Verified (No Changes Needed)
-
SwiftWarplyFramework/SwiftWarplyFramework/Network/NetworkService.swift
- Basic auth implementation was already correct