使用AFOAuth2Manager进行身份验证
我正在使用dribbble客户端,并且无法使用AFOAuth2Manager进行身份验证。我目前使用的是NXOAuth2Client,但是我刚刚遇到了AFOAuth2Manager,所以我想说一说。使用AFOAuth2Manager进行身份验证
使用NXOAuthClient,从服务器获取令牌没有问题。但是,当涉及到AFOAuth2Manager时,它总是返回一个错误。
这是我用NXOAuth2Client来初始化:
[[NXOAuth2AccountStore sharedStore] setClientID:kDRBClientID
secret:kDRBClientSecret
scope:[NSSet setWithObjects:@"public", @"write", @"comment", @"upload", nil]
authorizationURL:[NSURL URLWithString:kDRBAuthorizationURL]
tokenURL:[NSURL URLWithString:kDRBTokenURL]
redirectURL:[NSURL URLWithString:kDRBRedirectURL]
keyChainGroup:kDRBAccountType
forAccountType:kDRBAccountType];
使用我试图用AFOAuth2Manager给init这样相同的常数:
NSURL *baseURL = [NSURL URLWithString:kDRBBaseUrl];
AFOAuth2Manager *OAuth2Manager =
[[AFOAuth2Manager alloc] initWithBaseURL:baseURL
clientID:kDRBClientID
secret:kDRBClientSecret];
OAuth2Manager.useHTTPBasicAuthentication = NO;
NSDictionary *dictionary = @{@"scope" : @"public write",
@"redirect_uri" : kDRBRedirectURL};
[OAuth2Manager authenticateUsingOAuthWithURLString:@"/oauth/authorize"
parameters:dictionary
success:^(AFOAuthCredential *credential) {
NSLog(@"Token: %@", credential.accessToken);
}
failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
标志在dribbble第一流量直接将用户登录到登录页面(即/ oauth/authorize页面),在用户输入用户名和密码后,它会将用户重定向到给定的redirectURL。
我现在的问题是我甚至无法进入登录页面。有人能澄清我在做什么错吗? (我也尝试了AFOAuth2Manager中的不同身份验证方法,但都没有工作)。
我对OAuth2非常陌生,请耐心等待。
更新
这里的错误日志:
Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: client error (422)" UserInfo=0x7fb02ad2de00 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fb02ad6e200> { URL: https://dribbble.com/oauth/authorize } { status code: 422, headers {
Connection = close;
"Content-Length" = 47;
"Content-Type" = "application/json; charset=utf-8";
Date = "Sat, 08 Aug 2015 23:52:20 GMT";
Server = "nginx/1.4.6 (Ubuntu)";
Status = "422 Unprocessable Entity";
"X-Request-Id" = "8489a5f0-206a-48ff-b6e7-81664fc6b6f5";
"X-Runtime" = "0.006667";
} }
随着NXOAuth2Client,它会在页面准备一个网址为标志与我的PARAMS这样的:
https://开头dribbble.com/oauth/authorize?client_id=my_client_id & scope = write%20comment%20upload%20public & redirect_uri = my_redirect_uri & response_type =代码
但我注意到,与AFOAuth2它会在https://dribbble.com/oauth/authorize引发错误。它不会将我的参数附加到请求url?
添加以下行发出请求
OAuth2Manager.responseSerializer = [AFJSONResponseSerializer serializer];
之前,422 Unprocessable Entity - 服务器无法处理所包含的指令。请求格式良好,但由于语义错误无法遵循。
例如,如果XML请求主体包含格式正确(即,语法正确)但语义错误的XML指令,则可能会出现此错误情况。
感谢您的回复。我将建议的代码行添加到代码中,但它抛出了相同的错误。 –
什么是错误?更新有问题的错误。 –
嗨,我刚刚更新错误日志的帖子。谢谢! –