2016-07-24 67 views
1

我正在用auth0在反应应用程序中进行LinkedIn身份验证。我在设置中设置了回拨URL中的localhost:3000/upload,在用户登录localhost:3000/login后跳转,他们将重定向到localhost:3000/upload。但是,我总是得到这个错误:url localhost:3000/login不在回调网址列表中。为什么auth0希望返回到登录后登录的页面?不是它应该是一些不同的URL。它对我来说没有意义。Auth0回调URL不匹配

编辑:

export default class AuthService { 
    constructor(clientId, domain) { 
    // Configure Auth0 
    const options = { 
     allowedConnections: ['linkedin'], 
     auth: { 
     params: {responseType: 'code'} 
     } 
    }; 
    this.lock = new Auth0Lock(clientId, domain, options) 
    // Add callback for lock `authenticated` event 
    this.lock.on('authenticated', this._doAuthentication.bind(this)) 
    // binds login functions to keep this context 
    this.login = this.login.bind(this) 
    this.loggedIn = this.loggedIn.bind(this) 
    } 

    _doAuthentication(authResult){ 
    // Saves the user token 
    console.log(authResult); 
    this.setToken(authResult.idToken) 
    this.lock.getProfile(authResult.idToken, (error, profile) => { 
     if (error) { 
     console.log('Error loading the Profile', error) 
     } else { 
     console.log(profile) 
     } 
    }) 
    } 
//.... 

回答

3

请确保两两件事:

1)。在您的反应应用程序代码

responseType: 'code' 

2)。在Auth0仪表板的设置 - >允许的回调URL中,放置您的回调条目(本地主机:3000 /上传) - 我认为您已完成,但以防万一。

enter image description here

让我知道如果你仍然有问题。

+0

嘿,谢谢你的回答。我做了你的建议,但它仍然指引我进行身份验证的相同网址。 –

+0

对于反应应用程序,您应该使用隐式授予流程......所以在这种情况下,请使用responseType = token并使用事件侦听器,因为您的操作是我的建议。合理? – arcseldon

+0

@shangsunset - 你解决了吗? – arcseldon

1

要在成功验证后会重定向到一个不同的URL,你需要提供redirectUrl要锁定,就像这样:

//配置Auth0 常量选项= { allowedConnections:“LinkedIn”] , auth:{ responseType:'code', redirectUrl:'http://localhost:3000/upload' } };
this.lock =新Auth0Lock(的clientId,域选项)

(另请注意,responseType选项去auth下,不根据auth.params。)

如果你做的重定向,你将不会达到您在登录页面中定义的事件处理程序。您需要在目标页面添加事件处理程序(并使用responseType:token)或在服务器代码中处理认证结果(如果您要求responseType: code,通常会这样做)。

0

确保在将URL粘贴到Auth0 Setting站点时,URL之间的逗号之间没有特殊的隐藏字符或空格。我没有意识到这个util我把每一个网址到Vim来检查,看看有这样的情况下