短篇小说到自己的服务器配置
在Symfony2中使用GTM-的oauth2 iOS和FOSOAuthServerBundle实现我自己的oauth2服务器,我没有得到回调finishedSelector
GTM-的oauth2访问。
这是“特殊”的ViewController创建:
GTMOAuth2ViewControllerTouch * viewController;
viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:myAuth
authorizationURL:authURL
keychainItemName:nil
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
什么是可能使finishedSelector的原因,(该实现的方法viewController:finishedWithAuth:error
)没有被调用?
我得到的行为是登录页面已正确呈现,但它充当整个Web应用程序的起点,在登录后呈现其余页面,而不是将控件返回到finishedSelector最后是必须管理APP工作流程延续的视图控制器。
说来话长
在Symfony2中使用GTM-的oauth2和FOSOAuthServerBundle,我遇到问题,努力使arquitecture赶上登录,并从我的iOS应用程序加载的认证会话。
我遵循gtm-oauth2 documentation中描述的说明,特别是Signing in to non-Google Services部分。
做什么,它是存在的描述,我对创建auth
对象这个方法:
- (GTMOAuth2Authentication *) authForMyAPP
{
//This URL is defined by the individual 3rd party APIs, be sure to read their documentation
NSString * url_string = @"http://myHost/oauth/v2/token";
NSURL * tokenURL = [NSURL URLWithString:url_string];
// We'll make up an arbitrary redirectURI. The controller will watch for
// the server to redirect the web view to this URI, but this URI will not be
// loaded, so it need not be for any actual web page. This needs to match the URI set as the
// redirect URI when configuring the app.
NSString * redirectURI = @"http://myHost/oauth/v2/falseCallBack";
GTMOAuth2Authentication * myAuth;
myAuth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"MyAPP"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:kMyClientID
clientSecret:kMyClientSecret
];
//[myAuth setTokenType:@"Bearer"];
return myAuth;
}
然后,此方法创建的“特殊”的viewController应该处理渲染登录页面和返回的执行登录时的控制:
- (void)signInToMyAPP()
{
GTMOAuth2Authentication *myAuth = [self authForMyAPP];
NSString* auth_string = @"http://127.0.0.1/~pgbonino/Symfony/web/app.php/oauth/v2/auth";
NSURL * authURL = [NSURL URLWithString:auth_string];
// Display the authentication view
// Creates the "special" viewController passing the `auth` object, the authorization URL and the finishedSelector
GTMOAuth2ViewControllerTouch * viewController;
viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:myAuth
authorizationURL:authURL
keychainItemName:nil
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[self.navigationController pushViewController:viewController animated:YES];
}
最后,我有方法用于finishedSelector。一旦登录正确执行并且认证成功(或出现错误),应该调用它。这是什么,我没办法去完成:
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)myAuth
error:(NSError *)error
{
if (error != nil)
{
// Authentication failed
UIAlertView *alertView = [ [UIAlertView alloc] initWithTitle:@"Authorization Failed"
message:[error localizedDescription]
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alertView show];
}
else
{
// Authentication succeeded
// Assign the access token to the instance property for later use
//self.accessToken = myAuth.accessToken;
[myAuth setShouldAuthorizeAllRequests:YES];
[[Singleton sharedSingleton] setAuth:myAuth];
// Display the access token to the user
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Authorization Succeeded"
message:[NSString stringWithFormat:@"Access Token: %@", myAuth.accessToken]
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alertView show];
}
}
这一切都应该使我的登录页面的Web视图,赶上成功登录调用viewController:finishedWithAuth:error
并保存在一些共享对象的会话。
尽管如此,我得到的行为是我在Web视图中呈现了登录信息,我正确登录,而代之以被调用的委托选择器,它通常只是登录应用程序,下一页被加载网络视图,就好像它在一个普通的浏览器中一样。所以回调不会被执行。
为什么我不能调用选择器?任何想法?
重要提示:Oauth2服务器工作正常:如果我从Safari中调用令牌URL和callBack url,一切正常。令牌和授权码被正确保存在数据库中。