I’m trying to authenticate on my Python server with the Authorization header that AFNetworking sets. Before I do the request, I set my AFNetworking client like this:
// global.globalAFHTTPClient is my AFclient in this case
[global.globalAFHTTPClient setAuthorizationHeaderWithUsername:global.userEmail
password:global.password];
On the server, I can access the header like this:
self.request.headers['Authorization']
My question then is, on the server, how do I pull the username and password from the Authorization header? Do I need to decode the Base64 encoding first? Do I treat the header like a dictionary?
Is this the correct way to do it?
authorizationHeader = self.request.headers['Authorization']
username = authorizationHeader['username']
password = authorizationHeader['password']
You need to decode it first. In your example you just need to decode “KG51bGwpOihndWxsKQ==”. This should decode to a string with the format ‘username:password’.
There could be some libraries that could do this for you, but it depends on your server stack.