Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"];
like image 443
DaynaJuliana Avatar asked Mar 18 '23 07:03

DaynaJuliana


1 Answers

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

like image 113
DaynaJuliana Avatar answered Mar 29 '23 02:03

DaynaJuliana