2016-12-14 27 views
0

我使用Auth0 Lock與google-oauth2連接,我需要獲得refresh_token,因爲我需要在用戶離線時從服務器端進行API調用。Auth0 Lock - Google oauth2無法獲取refresh_token

我按照他們的指導,但它不工作,refreshToken總是undefined

使用http://cdn.auth0.com/js/lock/10.7.2/lock.min.js

this.lock = new Auth0Lock('...', 'xxx.eu.auth0.com', { 
    initialScreen:'login', 
    allowedConnections: ['google-oauth2'], 
    allowSignUp: false, 
    auth: { 
    redirect: false, 
    responseType: "token", 
    params: { 
     'access_type': 'offline', 
     'approval_prompt': 'force', 
    }, 
    }, 
    autoclose: true 
}); 

也試圖與這裏params 'approval_prompt': 'force''prompt': 'select_account consent'

說明:https://github.com/auth0/rules/blob/master/rules/google-refresh-token.md

回答

2

這條規則是錯誤的。 IdP access_tokens可通過管理API獲得。看到這個端點:https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id

需要一個特殊的範圍(read:user_idp_tokens)。

這是因爲的IdP令牌是敏感的工件,所以Auth0提出了額外的安全層,以獲得它們。

您當然可以從規則中調用API,但我們可能會建議您不要這樣做,而是讓您的後端代表您的(前端)應用程序行事。

+0

我不知道我理解正確。 我有一個SPA應用程序,我想連接到Node中的後端。 在SPA我使用的鎖,你告訴我,我需要使用管理API(我想在服務器上),但我不完全明白,我怎麼就能獲得'refresh_token'。 Auth0是否將refresh_token保存在某個地方以供我在之後進行檢索? – mtt

+0

的refresh_token(谷歌一個,這是)被authentoication後取出,並作爲在Auth0用戶配置文件的一部分被存儲。要檢索它,你可以使用我上面寫到的端點。您可以通過登錄然後使用API​​瀏覽器輕鬆地看到這一點。 IdP(Google)令牌(包括access_token和refresh_token)將位於Identities數據結構下。 –

+0

現在很清楚,謝謝Eugenio!並感謝偉大的產品是Auth0! – mtt

相關問題