2017-10-06 13 views
0

Auth0有一個非常棒的文檔,有時即使您通讀它1000次,但它對我個人來說沒有意義,所以希望也許別人也有類似的問題。開發環境的Auth0回調重定向

我想要什麼?

II I從與auth0.WebAuth物體看起來像這樣編譯我的本地主機環境進行登錄:

auth0 = new auth0.WebAuth({ 
    clientID: 'adscsdcascascascasdcsdac', 
    domain: 'webatom.auth0.com', 
    responseType: 'token id_token', 
    audience: 'https://api.webatom.com', 
    redirectUri: 'http://localhost:5000/callback',   
    scope: 'openid profile' 
}); 

我想它重定向開發商到本地主機。

如果我登錄(或用戶登錄)從生產environemnt即。從jtrade.pro我希望他們被重定向到jtrade.pro/callback。很明顯,在量產版的物體看起來像這樣(用不同的重定向URI):

auth0 = new auth0.WebAuth({ 
    clientID: 'adscsdcascascascasdcsdac', 
    domain: 'webatom.auth0.com', 
    responseType: 'token id_token', 
    audience: 'https://api.webatom.com', 
    redirectUri: 'http://jtrade.pro/callback',   
    scope: 'openid profile' 
}); 

據我瞭解,那你是怎麼做的。通過uri,如果uri被列入白名單並在客戶端設置中逗號分隔,您將被重定向到所需的頁面。美麗,我列入白名單和逗號分隔。

最後一步,託管頁面。

var lock = new Auth0Lock(config.clientID, config.auth0Domain, { 
    auth: { 
    redirectUrl: config.callbackURL, 
    responseType: 'token', 
    params: config.internalOptions 
    }, 
    assetsUrl: config.assetsUrl, 
    allowedConnections: connection ? [connection] : null, 
    rememberLastLogin: !prompt, 
    language: language, 
    languageDictionary: languageDictionary, 
    theme: { 

    }, 
    prefill: loginHint ? { email: loginHint, username: loginHint } : null, 
    closable: false, 
}); 

重定向URL設置爲config.callbackURL這是因爲據我瞭解,使auth0看着白名單,看看所提供的URI的人在這裏,將用戶重定向,如果它是。

但是,這不會發生。 Auth0僅將用戶重定向到白名單中的第一個uri。我找不到適合此問題的解決方案。希望有人遇到這種情況。

回答

0

檢查了上述情況,我看到的行爲是不同的 - Auth0正確地使用了傳入的redirectUri。您應該仔細檢查所有設置,您的設置/配置有問題。下面,是發現的概括:

enter image description here

客戶端應用(用於反應的樣品開箱):

auth0 = new auth0.WebAuth({ 
    domain: AUTH_CONFIG.domain, 
    clientID: AUTH_CONFIG.clientId, 
    redirectUri: AUTH_CONFIG.callbackUrl, 
    audience: `https://${AUTH_CONFIG.domain}/userinfo`, 
    responseType: 'token id_token', 
    scope: 'openid' 
    }); 

轉換爲每個下面的:

https://demo.auth0.com/login?client=zalZ1MxxxxxxxxxxxZ5xfZga&protocol=oauth2&redirect_uri=http://localhost:3000/callback&response_type=token id_token&scope=openid&audience=https://demo.auth0.com/userinfo&nonce=2OfVCpn-4Ka9k33h50Y5YjNgw8nsxE5B 

https://demo.auth0.com/login?client=zalZ1MxxxxxxxxxxxZ5xfZga&protocol=oauth2&redirect_uri=http://localhost:3001/callback&response_type=token id_token&scope=openid&audience=https://demo.auth0.com/userinfo&nonce=kDNsP5Sfp1M0ydJ57h7eG.S_sNkO7gRs 

使用默認的Auth0 HLP,您將擁有以下內容:

<script src="https://cdn.auth0.com/js/lock/10.18/lock.min.js"></script> 
    <script> 
    // Decode utf8 characters properly 
    var config = JSON.parse(decodeURIComponent(escape(window.atob('@@[email protected]@')))); 
    config.extraParams = config.extraParams || {}; 
    var connection = config.connection; 
    var prompt = config.prompt; 
    var languageDictionary; 
    var language; 

    if (config.dict && config.dict.signin && config.dict.signin.title) { 
     languageDictionary = { title: config.dict.signin.title }; 
    } else if (typeof config.dict === 'string') { 
     language = config.dict; 
    } 
    var loginHint = config.extraParams.login_hint; 

    var lock = new Auth0Lock(config.clientID, config.auth0Domain, { 
     auth: { 
     redirectUrl: config.callbackURL, 
     responseType: (config.internalOptions || {}).response_type || 
      config.callbackOnLocationHash ? 'token' : 'code', 
     params: config.internalOptions 
     }, 
     assetsUrl: config.assetsUrl, 
     allowedConnections: connection ? [connection] : null, 
     rememberLastLogin: !prompt, 
     language: language, 
     languageDictionary: languageDictionary, 
     theme: { 
     //logo:   'YOUR LOGO HERE', 
     //primaryColor: 'green' 
     }, 
     prefill: loginHint ? { email: loginHint, username: loginHint } : null, 
     closable: false, 
     // uncomment if you want small buttons for social providers 
     // socialButtonStyle: 'small' 
    }); 

    lock.show(); 
    </script> 

這會正確回撥到原始回調URL(redirectUri)中分配的端口上的客戶端。

0

問題是,不是調用將用戶重定向到/ authorize端點的方法auth0.authorize(),而是對url進行了硬編碼,並將用戶重定向到/ login端點,並且不在params中包含任何數據(即在url字符串內)。如果你願意,你不必使用你自己也可以自己構造字符串的方法。該方法的完整指南可以找到here