2013-01-13 63 views
-1

短篇小說到自己的服務器配置

在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,一切正常。令牌和授權碼被正確保存在數據庫中。

回答

0

忘掉它吧。

這只是我。

的OAuth2將與Symfony2中和FOSUserBundle而這個參數設置爲true config.yml不起作用:

always_use_default_target_path: false 
相關問題