All authorizations are done through the AFNetworking
library. The authorizations are mentioned in the following sections.
To authorize against the basic (or the simplest) authorization:
// client is instance of AFHTTPClient [client setAuthorizationHeaderWithUsername:@"username" password:@"password"];
The token-based authorization is mostly used with OAuth 1.0 / OAuth 2.0 authorization schemes. After authorizing with them, you will get a token string, which you need to supply to your AFHTTPClient
:
// client is instance of AFHTTPClient NSString *token = @"1q2w3e4r"; [client setAuthorizationHeaderWithToken:token];
Here, the setAuthorizationHeaderWithToken
method actually sets an HTTP header Authorization
with the Token token=1q2w3e4r
value. Sometimes, the web service you are using will require more custom HTTP headers to be set. For such cases, use setDefaultHeader:value:
of AFHTTPClient
:
[client setDefaultHeader:@"MongoHQ-API-Token" value:@"1q2w3e4r"];