2015-02-17 77 views
0

我試圖將一些功能從Sinatra應用程序移植到Rails應用程序。在Sinatra應用程序中,代碼工作正常。當我將代碼帶入Rails時,它失敗了。我懷疑它是如何傳遞config.pk文件的,但是在幾個小時後我仍然不知道。我怎樣才能成功從KeyUtils獲得密鑰?Google APIClient - 無效的密鑰文件或密碼

$ cd path/to/app 
app $ rails c 
Loading development environment (Rails 4.2.0.rc2) 
2.1.2 :001 > key_file_path = Rails.root.join('config.p12').to_s 
2.1.2 :002 > key_file = File.read(key_file_path) 
2.1.2 :003 > passphrase = 'notasecret' 
2.1.2 :004 > require 'google/api_client' 
2.1.2 :005 > key = Google::APIClient::KeyUtils.load_from_pkcs12(key_file, passphrase) 
ArgumentError: Invalid keyfile or passphrase 
2.1.2 :006 > key = Google::APIClient::KeyUtils.load_from_pkcs12(key_file_path, passphrase) 
ArgumentError: Invalid keyfile or passphrase 
2.1.2 :007 > key_file.length 
=> 4330 
2.1.2 :008 > key_file 
=> "3082 06c0 0201 0330 8206 7a06 092a 8648\n86f7 0d01 0701 a082 066b 0482 0667 3082\n0663 3082 0328 0609 2a86 4886 f70d 0107\n01a0 8203 1904 8203 1530 8203 1130 8203\n0d06 0b2a 8648 86f7 0d01 0c0a 0102 a082\n02b2 3082 02ae 3028 060a 2a86 4886 f70d\n010c 0103 301a 0414 a6bd 5765 7b62 fcbd\ncccf 4e26 [... key file abbreviated ...] 5270\n0202 0400 " 

文件夾結構

my_rails_root_folder 

|_ config.p12 

我想按照這個谷歌文檔以及: https://github.com/tpitale/legato/wiki/OAuth2-and-Google#application-code

在此先感謝。

回答

0

經過很長一段時間的苦苦掙扎後,我複製了原始文檔並將副本放入新應用中。然後一切又開始工作。

之前,我已經複製了證書的內容,而不是文件本身。顯然這還不夠好,我不得不復制整個文件。

相關問題