Skip to content
This repository was archived by the owner on Jan 17, 2023. It is now read-only.

setAuthorizationHeaderFieldWithCredential: produces wrong header #117

Closed
rajderks opened this issue Mar 24, 2016 · 1 comment
Closed

setAuthorizationHeaderFieldWithCredential: produces wrong header #117

rajderks opened this issue Mar 24, 2016 · 1 comment

Comments

@rajderks
Copy link

(talking about the 3.0.0. branch here)

When using setAuthorizationHeaderFieldWithCredential: the library produces the following header field

Authorization = "Basic <wrong token here>";

To my knowledge, it should be
Authorization = "Bearer <token here>";

Also, the token in the 'Basic' case is NOT the access token stored in the AFOAuthCredential for given provider identifier.

When setting the Authorization header myself with the bearer keyword and my valid access token the call works.

@buranmert
Copy link

Commit: cafa193

Inside AFOAuth2Manager's designated initializer method:

- (id)initWithBaseURL:(NSURL *)url
 sessionConfiguration:(NSURLSessionConfiguration *)configuration
             clientID:(NSString *)clientID
               secret:(NSString *)secret {
    ...
    self.useHTTPBasicAuthentication = YES;
    ...
}
- (void)setUseHTTPBasicAuthentication:(BOOL)useHTTPBasicAuthentication {
    _useHTTPBasicAuthentication = useHTTPBasicAuthentication;

    if (self.useHTTPBasicAuthentication) {
        [self.requestSerializer setAuthorizationHeaderFieldWithUsername:self.clientID password:self.secret];
        } else {
            [self.requestSerializer setValue:nil forHTTPHeaderField:@"Authorization"];
        }
    }
}

So this is automatically done:

Authorization = "Basic ";

When you call setAuthorizationHeaderFieldWithCredential: method, your credential must pass an if clause to turn your HTTP header field into Authorization = "Bearer <token here>"; which is:

- (void)setAuthorizationHeaderFieldWithCredential:(AFOAuthCredential *)credential {
    if ([credential.tokenType compare:@"Bearer" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
        [self setValue:[NSString stringWithFormat:@"Bearer %@", credential.accessToken] forHTTPHeaderField:@"Authorization"];
    }
}

Are you sure your credential's tokenType is Bearer?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants