auth0登录时进程卡在回调url



我正在做React项目,并将auth0与之集成。我已经完成了所有步骤,但有一点停滞不前。当我要使用Gmail帐户使用auth0登录时,它停留在回调URL上,进程停止。在回调URL之后不调用handleAuthentication方法。我该如何解决这个问题??

export default class Auth {
auth0 = new auth0.WebAuth({
domain: AUTH_CONFIG.domain,
clientID: AUTH_CONFIG.clientId,
redirectUri: 'http://localhost:3000/callback',
audience: `https://${AUTH_CONFIG.domain}/userinfo`,
responseType: 'token id_token',
scope: 'openid'
});
constructor() {
console.log('process.env.NODE_ENV',process.env.NODE_ENV)
this.login = this.login.bind(this);
this.logout = this.logout.bind(this);
this.handleAuthentication = this.handleAuthentication.bind(this);
this.isAuthenticated = this.isAuthenticated.bind(this);
}
login() {
this.auth0.authorize();
console.log('login done',store)
}
handleAuthentication() {
console.log('asdfasfasf')
this.auth0.parseHash((err, authResult) => {
console.log('authResult.accessToken',authResult.accessToken)
if (authResult && authResult.accessToken && authResult.idToken) {
this.setSession(authResult);
localStorage.setItem("user_id", "user-id");
let store1 = store();
store1.dispatch({ type: 'LOGIN_USER_SUCCESS', payload: authResult })
window.location.replace('/')
} else if (err) {
console.log(err);
alert(`Error: ${err.error}. Check the console for further details.`);
}
});
}
}

我知道现在回答这个问题有点晚了,但以防万一它能帮助未来的某个人,或者至少指向正确的方向。

我也有同样的问题,问题是这条线

redirectUri: 'http://localhost:3000/callback',

如果您以http://localhost:3000的身份访问localhost,那么您现有的回调应该可以工作。

但是,重定向URL不适用于http://www.localhost:3000。url将在回调时卡住。我认为auth0组件对路由非常具体。它确实区别对待www和没有www的www,尽管它们指向同一个域。

为了使这对www和非www都有效,我将重定向Uri url更改为以下

redirectUri:${window.location.origin}/callback

p.S:一旦做出了这个更改,也不要忘记调整auth0站点上的回调,以允许这两种变体。

最新更新