2013-01-03 31 views
0

我在Google App Engine應用程序中使用Python OAuth2裝飾器。我從API控制檯下載了客戶端機密信息作爲json文件。將應用程序部署到appspot.com後,本地版本(localhost:8080)不起作用。對decorator.has_credentials()的調用返回false。 appspot版本正常工作。oauth2decorator_from_clientsecrets部署後在開發服務器中導致錯誤

UPDATE:代碼段(簡體)

CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json') 

oauth2_decorator = oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS, 
    scope='https://www.googleapis.com/auth/calendar', 
    message=MISSING_CLIENT_SECRETS_MESSAGE) 


class MyRequestHandler(webapp2.HandleRequest): 
    @oauth2_decorator.oauth_aware 
    def get(self): 
    if oauth2_decorator.has_credentials(): 
     # do stuff... 
    else: 
     self.out.write("<html><body>Invalid credentials</body></html>") 


app = webapp2.WSGIApplication([ 
    ('/', MyRequestHandler), 
    (oauth2_decorator.callback_path, oauth2_decorator.callback_handler()) 
], debug=True) 

更新2:這是我的client_secrets.json的內容,而不敏感信息

{"web": 
    { 
    "auth_uri":"https://accounts.google.com/o/oauth2/auth", 
    "client_secret":"MY_CLIENT_SECRET", 
    "token_uri":"https://accounts.google.com/o/oauth2/token", 
    "client_email":"[email protected]", 
    "redirect_uris":[ 
     "http://MY_APP_NAME.appspot.com", 
     "http://localhost:8080" 
    ],  
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]", 
    "client_id":"MY_CLIENT_ID.apps.googleusercontent.com", 
    "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs", 
    "javascript_origins":[ 
     "http://MY_APP_NAME.appspot.com", 
     "http://localhost:8080" 
    ] 
    } 
} 

我越來越「無效的憑據「在我的本地機器。在appspot.com中運行良好。它在我的機器中工作,然後在appspot中進行部署。

會發生什麼?

在此先感謝

+0

你能發表一個代碼片段展示你如何使用裝飾器? – proppy

+0

當然可以。我剛剛完成。 – jorgeas80

+0

您可以添加client_secrets.json的內容(刪除敏感信息後)嗎? – proppy

回答

0

好的,我太愚蠢了。我忘了第一次爲用戶提供授權鏈接,而不是錯誤。

CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json') 

oauth2_decorator = oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS, 
    scope='https://www.googleapis.com/auth/calendar', 
    message=MISSING_CLIENT_SECRETS_MESSAGE) 


class MyRequestHandler(webapp2.HandleRequest): 
    @oauth2_decorator.oauth_aware 
    def get(self): 
    if oauth2_decorator.has_credentials(): 
     # do stuff... 
    else: 
     self.out.write(oauth2_decorator.authorize_url()) 


app = webapp2.WSGIApplication([ 
    ('/', MyRequestHandler), 
    (oauth2_decorator.callback_path, oauth2_decorator.callback_handler()) 
], debug=True) 

現在它工作正常:-)。

相關問題