2016-01-21 106 views
1

我一直在尋找https://github.com/rfdickerson/watson-translation-demo,它試圖展示如何使用iOS上的Facebook OAuth和NodeJS後端進行身份驗證。Watson iOS SDK身份驗證

iOS的代碼很簡單:

let token: String = FBSDKAccessToken.currentAccessToken().tokenString 

let fbAccess = FacebookAuthenticationStrategy(
    tokenURL: "https://watsonsdkdemo.mybluemix.net/language-translation-service/api/v1/token", 
    fbToken: token) 
translateService = LanguageTranslation(authStrategy: fbAccess) 

的問題是,服務器/ app.js有

var creds = appEnv.getServiceCreds(/facebook-authentication/) || {} 

和manifest.yml具有

- services: 
    - facebook-authentication 

但是,當您將cf push腳本轉換爲您獲得的Bluemix帳戶:

FAILED 
Could not find service facebook-authentication to bind to xxxxxxx 

問題是作者描述'facebook-authentication'服務是什麼地方。

在服務器部署說明他們有

$ cf login 
$ cf create-service speech_to_text standard speech-to-text-service 
$ cf create-service text_to_speech standard text-to-speech-service 
$ cf create-service language_translation standard language-translation-service 
$ cf env 
$ cd server 
$ cf push 

沒有說明Facebook的身份驗證服務是什麼。

+0

我給回覆的作者留言並要求他回覆。 –

回答

0

我很抱歉,說明不完整。 Facebook認證應該是用戶提供的服務。您可以使用cf create-user-provided-service command創建它:

CF創建用戶提供的服務的Facebook的身份驗證-p「APP_SECRET_GOES_HERE」

的想法是,當您註冊一個Facebook應用程序,他們給你的應用程序的祕密。由於該祕密不應該嵌入到源代碼中,因此您可以通過創建自定義服務將其設置在環境變量VCAP中,以便爲您提供該信息。

請注意,我沒有完成實際使用應用程序祕密來檢查憑據的合法性。儘管這是中間人攻擊的一個小安全漏洞,但是Facebook標記檢查仍然有效,因爲在Facebook應用程序設置中,我使得它不需要使用應用程序密鑰。現在,只需創建用戶服務並將其值設置爲任何您想要的值。

希望這會有所幫助!

+0

好的,它的工作原理!當我在任何原因的命令行上提供「APP_SECRET_GOES_HERE」時,它會給我一個「>」提示。在檢查命令幫助,它似乎說它就像 cf創建用戶提供的服務my-db-mine -p'{「username」:「admin」,「password」:「pa55woRD」}' 其實我在「提示符」和「bluemix」Web界面環境變量中鍵入退出,它將其顯示爲「用戶提供的」 :[ {name}:「facebook-authentication」, 「label」:「user-provided」 「credentials」:{ 「APP_SECRET_GOES_HERE」:「退出」 } } ] – 68882

+0

太棒了!很高興它對你有效。 –