我有一個棘手的問題。我需要使用iOS應用啓動Google身份驗證,並將Google API返回到我創建的服務器端點的code
值。如果我從JavaScript
應用程序發起請求,這很好。 Here Google文檔。但是,如果我使用以下代碼從iOS應用程序啓動請求,則會返回並說我有一個URI不匹配,因爲我創建的oAuth ID是Web Application
類型。如果我使用Other
,我會得到另一個錯誤,即Error fetching OAuth2 access token, message: 'invalid_grant: Invalid code.'.
redirect_uri_mismatch嘗試使用Google API進行身份驗證時
話雖如此,以下是我如何從iOS應用程序啓動身份驗證。
NSString *urlString = @"https://accounts.google.com/o/oauth2/token";
NSURL *tokenURL = [NSURL URLWithString:urlString];
// 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.
NSString *redirectURI = @"urn:ietf:wg:oauth:2.0:oob";
GTMOAuth2Authentication *auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"Google"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:kClientID
clientSecret:kClientSecret];
您是否看到任何明顯的問題?
阿爾貝託,謝謝,但'redirectURI'這裏是iOS應用任意值。這至少是文件所說的。 如果你不這麼認爲,redirect_uri應該是什麼?它是我的服務器API的完全合格路徑嗎? –
redirectURI應該是服務器中文件夾或文件的完全限定部分。 https://developers.google.com/api-client-library/php/auth/web-app –