2012-06-01 23 views
0

我開始第一次嘗試製作mac應用程序,並且業務的第一順序是使用OAuth和Soundcloud對應用程序進行身份驗證。發送授權請求很簡單,但是我堅持的是如何從Soundcloud收聽重定向。如何聆聽原生可可應用程序的OAuth2重定向uri

我已經在info.plist中設置了我的URL方案,並將我的應用程序設置爲偵聽傳入請求,但是當我嘗試註冊時,我沒有得到響應。我已經用safari測試過這個網址,它運行良好。

這裏的代碼片斷從我的應用程序的委託:

- (void) applicationDidFinishLaunching:(NSNotification *)aNotification 
{ 
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager]; 
[appleEventManager setEventHandler:self 
         andSelector:@selector(handleGetURLEvent:withReplyEvent:) 
        forEventClass:kInternetEventClass andEventID:kAEGetURL]; 

[[NXOAuth2AccountStore sharedStore] setClientID:@"myClientID" 
             secret:@"superSecretSecret" 
           authorizationURL:[NSURL URLWithString:@"https://soundcloud.com/connect"] 
             tokenURL:[NSURL URLWithString:@"https://api.soundcloud.com/oauth2/token"] 
            redirectURL:[NSURL URLWithString:@"myApp://connect"] 
           forAccountType:@"iHopeThisWorks"]; 

} 

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent 
{ 
NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]]; 
} 

我的猜測是,的SoundCloud不知道在哪裏可以找到對myApp://連接,因爲它只是我的本地機器上存在。那麼,我是否需要創建一些中介,如處理http請求的Web服務?如果是這樣,中介如何知道如何連接到我的機器?很抱歉,如果這些是基本或誤導性的問題,但正如我之前所說的,這是我第一次發現類似這樣的情況,而我的谷歌搜索功能使我找不到解決方案。

回答

3

通常,OAuth服務提供商應該爲臺式機實施Resource Owner Password Credentials Grant--對於您的情況,他們不會。

但他們已經在OAuth2Client上做了一個包裝 - 在https://github.com/soundcloud/CocoaSoundCloudAPI上查找它。該文檔在http://developers.soundcloud.com/docs#authentication

回答你的問題的URI是myApp://connect如果你的應用程序字面意思myApp。請訪問vimeo上的開發者視頻:http://vimeo.com/28715664

最好的和閱讀文檔。

0

您可以使用NSWebView。 我知道這聽起來不太優雅,因爲您實際上並不需要「視圖」,但據我所知這是獲取重定向的最簡單解決方案。

相關問題