DaynaJuliana
DaynaJuliana

Reputation: 1164

Setting Auth. Token Header AFNetworking 2.0

I'm following the following method to my rails API, and need to send in an authorization token

  def restrict_access
   authenticate_or_request_with_http_token do |token, options|
    ApiKey.exists?(access_token: token)
  end
 end

The token works when passing in via curl in a header with format:

   -H 'Authorization: Token token = "tokenvalue"'

I'm having trouble translating this for my AFHTTPRequestOperationManager. How would I define the below to equal the above curl request ?

    [self setRequestSerializer:[AFHTTPRequestSerializer serializer]];
    [self.requestSerializer setValue:@"tokenvalue" forHTTPHeaderField:@"Authorization: Token"];

Upvotes: 4

Views: 3816

Answers (1)

DaynaJuliana
DaynaJuliana

Reputation: 1164

Was finally able to get this with:

[self.requestSerializer setValue:[NSString stringWithFormat:@"Token token=101010"] forHTTPHeaderField:@"Authorization"];

Both tokens needs to be on the value side

Upvotes: 7

Related Questions