reactjs - 如何从 loginwithPopup url 中删除 response_mode = web_message?
问题描述
我正在使用 Auth0 进行身份验证并做出反应。我正在使用 loginWithPopup()作为登录弹出屏幕。但是每次我最终都会遇到配置错误的错误(就像您在附件中看到的那样)。但是,如果我从它起作用的 URL 中删除 response_mode = web_message,有没有办法从代码中删除 response_mode。鉴于我的 auth0 快速入门,我正在使用 react-auth0-spa.js
import React, { Component, createContext } from 'react';
import createAuth0Client from '@auth0/auth0-spa-js';
// create the context
export const Auth0Context = createContext();
// create a provider
export class Auth0Provider extends Component {
state = {
auth0Client: null,
isLoading: true,
isAuthenticated: false,
user: false,
};
config = {
domain: "dev-ufnn-q8r.auth0.com",
client_id: "zZh4I0PgRLQqLKSPP1BUKlnmfJfLqdoK",
redirect_uri: window.location.origin,
//audience: "https://reachpst.auth0.com/api/v2/"
};
componentDidMount() {
this.initializeAuth0();
}
// initialize the auth0 library
initializeAuth0 = async () => {
const auth0Client = await createAuth0Client(this.config);
const isAuthenticated = await auth0Client.isAuthenticated();
const user = isAuthenticated ? await auth0Client.getUser() : null;
this.setState({ auth0Client, isLoading: false, isAuthenticated, user });
};
loginWithPopup = async () => {
try {
await this.state.auth0Client.loginWithPopup();
}
catch (error) {
console.error(error);
}
this.setState({
user: await this.state.auth0Client.getUser(),
isAuthenticated: true,
});
};
render() {
const { auth0Client, isLoading, isAuthenticated, user } = this.state;
const { children } = this.props;
const configObject = {
isLoading,
isAuthenticated,
user,
loginWithPopup: this.loginWithPopup,
loginWithRedirect: (...p) => auth0Client.loginWithRedirect(...p),
getTokenSilently: (...p) => auth0Client.getTokenSilently(...p),
getIdTokenClaims: (...p) => auth0Client.getIdTokenClaims(...p),
logout: (...p) => auth0Client.logout(...p)
};
return (
<Auth0Context.Provider value={configObject}>
{children}
</Auth0Context.Provider>
);
}
}
解决方案
经过一番研究,我找到了自己问题的答案。因此,如果我们使用response_mode = web_message,那么我们还需要在允许的 Web 源字段中配置我们的回调 URL。在我的情况下,我使用 loginWithPopup() 所以它通常会在登录 URL 中添加 response_mode = web_message 因为来自 auth0 SDK 的 loginWithPopup() 是PKCE + web_message https://auth0.com/docs/protocols/oauth2的组合(在响应模式如何工作?) https://auth0.com/blog/introducing-auth0-single-page-apps-spa-js-sdk(在幕后)
推荐阅读
- python - Creating savepoints and starting from a specific node in apache beam
- addeventlistener - 收听 Firefox WebExtension 侧边栏关闭
- java - 用 Kotlin 数据类替换 Java DTO 类的问题
- javascript - 使用正文执行获取请求 - 节点 js
- vba - 缺少所需列的 vba 错误处理
- php - PHP中的喜欢/不喜欢系统
- git - 需要在 git remote 上恢复提交
- php - Nginx、PHP - 发生错误。抱歉,您要查找的页面目前不可用。请稍后再试
- swift - 具有慢速互联网连接的 avplayer 在第一帧后无法正常工作
- android - 将 Google Play 服务版本从 11.2.2 升级到 15.0.0 后应用程序崩溃