동일한 요청에서 AFNetworking을 사용하여 기본 및 OAuth 인증 헤더를 사용할 수 있습니까 (덮어 쓰기 안 함)?기본 및 OAuth 인증 헤더를 동시에 사용
이 코드가 있습니다
NSURL *url = [NSURL URLWithString:@"https://www.infojobs.net/"];
AFOAuth2Client *OAuthClient = [[AFOAuth2Client alloc] initWithBaseURL:url clientID:kClientID secret:kClientSecret];
[OAuthClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[OAuthClient authenticateUsingOAuthWithPath:@"oauth/authorize" code:self.authorizationCode redirectURI:kInfoJobsRedirectURLString success:^(AFOAuthCredential *credential) {
NSLog(@"Credentials: %@", credential.accessToken);
if (![credential.accessToken isEqualToString:@""]) {
self.isAuthenticated = YES;
[AFOAuthCredential storeCredential:credential withIdentifier:@"kInfoJobsAccessToken"];
[[InfoJobsAPI sharedClient] setAuthorizationHeaderWithToken:credential.accessToken];
// (!) This overwrites the Authorization header set with the accessToken
[[InfoJobsAPI sharedClient] setAuthorizationHeaderWithUsername:kClientID password:kClientSecret];
success(credential);
}
} failure:^(NSError *error) {
NSLog(@"Error: %@", error.localizedDescription);
}];
을 그리고이 같은 요청해야합니다
GET /api/1/application HTTP/1.1
Host: api.infojobs.net
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Authorization: OAuth 07d18fac-77ea-461f-9bfe-a5e9d98deb3d
....
을하지만 "기본"과에서 "OAuth는"인증 헤더를 설정할 수 없습니다 AFNetworking이 보이는 것처럼이 헤더를 덮어 쓰는 것 같습니다. documentation
동일한 권한 부여 hea에서 "Basic"과 "OAuth"를 사용할 수 있습니다 der, 둘 다 "\ n"으로 나눌 수 있습니까?
감사하고, 내가 "기본"과 같은 헤더 "의 Oauth"인증을 사용할 수 있습니다
마지막으로 불쌍한 내 영어
편집 죄송합니다,이 코드는 다음과 같습니다
[[InfoJobsAPI sharedClient] setAuthorizationHeaderWithUsername:kClientID password:kClientSecret];
AFOAuthCredential *credential = [AFOAuthCredential retrieveCredentialWithIdentifier:@"kInfoJobsAccessToken"];
NSMutableURLRequest *request = [self requestWithMethod:@"GET" path:@"/api/2/candidate" parameters:nil];
[request addValue:[NSString stringWithFormat:@"OAuth %@", credential.accessToken] forHTTPHeaderField:@"Authorization"];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
DLog(@"Response : %@",JSON);
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
DLog(@"Error : %@",error);
}];
[operation start];
나는 당신의 솔루션이 어떻게 작동하는지 궁금합니다. 인증 헤더에 추가 값으로 "OAuth xxx (token) xxx"를 추가하면, 통신하고있는 서버가 Auth 헤더의 해당 부분을 확인한다는 것을 알고 있습니까? –