How To Add Authorization OAuth Request Header?

Nov 20, 2011 at 11:48 AM

How can I add an Authorization OAuth <ACS TOKEN> HEADER to each request using the SDK?  In Windows Phone, I create a partial class and use the context created method to do this.  How is it possible in the IOS SDK? 

Apr 7, 2012 at 1:33 AM

Figured it shortly after.  I created a category of the odata proxy.  As below:

--Entities+onBeforeHttpRequest.h

#import "Entities.h" //Your odatagen Proxy File

@interface Entities (Entities_onBeforeHttpRequest)

@end

 

--Entities+onBeforeHttpRequest.m

#import "Entities+onBeforeHttpRequest.h"

@implementation spotrEntities (spotrEntities_onBeforeHttpRequest)
- (void)onBeforeHttpRequest:(HttpRequest *)request {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"ACSUserToken"]) {
        NSString *accessToken = [defaults objectForKey:@"ACSUserToken"];
        HTTPHeaders *headers = [request getHeaders];
        NSMutableDictionary *headersDict = [headers getHttpHeaders];
        [headersDict setObject:[NSString stringWithFormat:@"OAuth %@", accessToken] forKey:@"Authorization"];
        [headers setHttpHeaders:headersDict];
        [request setM_httpHeaders:headers];
    }
}