ios - authenticate_or_request_with_http_token always returning false with AFNetworking -
before_filter :restrict_access def restrict_access authenticate_or_request_with_http_token |token, options| true end end
here can see i'm returning true authenticate_or_request_with_http_token
, attempt force work. however, i'm encountering extremely strange issue.
i'm sending in authorization
header value token token=token value here
the client here ios app using afnetworking.
when ios app calls on localhost:3000, works expected, , not 401 error.
with same exact code however, when run on remote server (heroku), 401.
however, 401 occurs on remote server when client ios app. when running via paw or postman, works fine. it's mind boggling.
here's ios code sets authorization header: [self.operationmanager.requestserializer setvalue:[nsstring stringwithformat:@"token token=%@", accesstoken] forhttpheaderfield:@"authorization"];
why running request ios simulator -> localhost work fine, running same request ios simulator -> heroku not work , result in 401?
and remember, authenticate_or_request_with_http_token
returning true. seems me heroku might modifying authorization header format, becomes invalid format, , block never called. authenticate_or_request_with_http_token
seems return false default if authorization header format screwed up, if pass in token=432
rather token token=432
.
figured out issue was. according nsurlrequest docs:
important
the nsurlconnection class , nsurlsession classes designed handle various aspects of http protocol you. result, should not modify following headers:
authorization
connection
host
www-authenticate
so issue you're not supposed modify authorization header. behind scenes, appears nsurlrequest modifying authorization header after had set it, , emptied out wasn't delivered. not sure why heroku , not localhost, there have it.
Comments
Post a Comment