HTTP Token #25
Comments
Hey Matt, sorry for the delayed response. You bring up a good point. I added a quick property for this – let me know if it works for you. Usage is simple: [[NSRConfig defaultConfig] setAdditionalHTTPHeaders:@{@"token" : @"ABC123"}]; From there on, every request (that uses that config (which is default)) will use that token header. |
Maybe I'm am not quite understanding the rails implementation of this, but I changed your lines to this
and set the config with
This is the only way I could get it to work? The header has to end up looking like this.
This is what the rails function looks like
Thanks again for the help |
Ah, I see. That's simple. Change the code back to the code I committed. The additional headers functions like a dictionary, so you'd want to use this key/value pair: NSMutableDictionary *token = [NSMutableDictionary dictionaryWithObject:@"Token token=d7c110c4396bf89251f581bfaf196280" forKey:@"Authorization"];
[[NSRConfig defaultConfig] setAdditionalHTTPHeaders:token]; |
Ok if I do that, it gives me this as the Authorization header
And there isn't any other header created. You think there is an issue with the decoder for the spaces? EDIT Ok hang on..... nevermind... somehow I was using some different code than you had here on the repo, all is well now, and it should have been from the start hah. Thanks again. |
I'm not sure I understand your result. The snippet I gave you would replicate exactly the tweak you had to do to my code. Are you sure the code in Request.m is changed back? And you're not using either HTTP Basic or OAuth as well right? What do you mean by "an issue with the decoder for the spaces"? |
My edit above, guess I should be more clear. I thought I reverted back to your code, but I guess I was playing around with it before and just didn't remember, so the code I thought was yours wasn't. What I get for staying up too late working. I put your original code from the commit back in and all is working as intended. Sorry for the confusion ha. |
No problem, glad to hear it! Closing this for now, feel free to reopen if anything else comes up. |
Sorry to bother you on a closed issue - but I'm trying to use 2.0.1 with RubyMotion and I can't find any sign of the setAdditionalHTTPHeaders method on NSRConfig. It looks like it's in the source here, but the version I'm getting thru Cocoapods (2.0.1) doesn't have it. Am I doing something stupid? For example, sould I expect something like this to work?
If not, how do I load up the requests with additional headers? |
Hi, no problem! I pushed a new version tag that includes that feature (2.0.2) -- Cocoapods should pick it up now. Sorry for the delay. |
Thanks for chasing that up. Much appreciated. How long do you think it will take to wash thru to the Cocoapods directory? I'm getting this at the moment:
|
I've noticed that the Cocoapods spec repo has not been updated fro 2.0.2 (which explains the problem above): https://github.com/CocoaPods/Specs/tree/master/NSRails Is that something that takes some time to wash thru? |
Hi there - I've tried using the pod directly form the Git repo in order to get 2.0.2 but I'm still having trouble setting any header variables. I can see the request hitting my rails app, but because i can't seem to set the auth token, the Rails app is rejecting the request. Here's the REPL output:
As you can see from the above, I can't set the headers because NSRConfig is not responding to the "additionalHTTPHeaders" property. Is there some way to check which version of the NSRConfig class I'm working with (at runtime)? |
Doing a bit more investigation, and I think there might be something wrong with the checked-in pod spec configuration in some way. Even when using the gem from GitHub with the tag = 2.0.2 setting, the Podfile.lock file in vendor/Podfile.lock is showing 2.0.1, even though the Podfile.lock in the root of the project shows 2.0.2. My project Podfile (in the root) of the project looks like this:
And this is what the Podfile.lock file from the root of the project looks like after a "pod install":
However, this is what vendor/Podfile.lock looks like after a "pod install"
I'd be the first to admit that I don't know very much about the internals of Podfiles, but this doesn't seem like it's correct to me. Am I doing something wrong? Or has the bump to 2.0.2 not quite worked properly? |
Hey guys, amazing work on this project. Makes it such a joy now to communicate with my rails back end. Just a quick question though. I noticed there is support in the config for oauth and basic authentication, but is there no option for using tokens? I am currently using authenticate_or_request_with_http_token on a project. But I can't seem to find a way to configure NSRails to put just a token field in the Authorization header for all of the requests. Any plans for including this?
Thanks
Matt
The text was updated successfully, but these errors were encountered: