react-native - React Native AuthSession.startAsync 登录成功后不关闭窗口
问题描述
我正在构建一个带有 react native 和 expo 的 web 应用程序。我正在尝试与 auth0 集成并调用授权 API。当我使用 AuthSession.startAsync 时,它会打开一个新窗口并重定向到 auth0,但是当我完成登录时,它不会将用户重定向回应用程序,而只会重定向到该弹出窗口中的 webapp。当我关闭窗口时,从 authSession.startAsync 返回的响应是:{type: "dismiss"}。它不会从 auth0 URL 获取参数。我不确定我做错了什么。
login = async () => {
// Retrieve the redirect URL, add this to the callback URL list
// of your Auth0 application.
const redirectUrl = AuthSession.getRedirectUrl();
console.log(`Redirect URL: ${redirectUrl}`);
// Structure the auth parameters and URL
let authUrl =
`${auth0Domain}/authorize` +
toQueryString({
client_id: auth0ClientId,
response_type: "token",
scope: "openid profile email",
redirect_uri: redirectUrl,
});
console.log(`AuthURL is: ${authUrl}`);
// Perform the authentication
const response: any = await AuthSession.startAsync({
authUrl: authUrl,
returnUrl: redirectUrl,
});
console.log("Authentication response", response);
if (response.type === "success") {
this.handleResponse(response.params);
}
};
handleResponse = (response: any) => {
if (response.error) {
Alert.alert(
"Authentication error",
response.error_description || "something went wrong"
);
return;
}
// Retrieve the JWT token and decode it
const jwtToken = response.id_token;
const decoded = jwtDecode(jwtToken);
const name = { decoded };
this.setState({ name });
};
解决方案
推荐阅读
- python - 如何在没有 anaconda 的情况下在 python 中创建环境?
- swift - 重写 NSScrollView.scrollWheel(with:) 方法禁用垂直滚动
- python - 尝试通过 Python 3.6 中的 filedialog 中的按钮获取所选文件的完整路径
- python - 有没有办法在使用 Pygame 库的函数调用之后使用绘制矩形?按下按钮后
- php - tymondesigns/jwt-auth:如何创建过期令牌?
- python - 需要将 Spark 转换为 Python 以将 DF 复制到 Azure SQL Server
- reactjs - 警告:React.createElement:类型无效——需要一个字符串(对于内置组件)或一个类/函数
- c# - C#方法Linq变量返回
- c - 我已经定义了我的函数,但仍然出现无法找到定义的错误
- javascript - 在 VueJS 应用程序中添加 Three.JS 'OrbitControls' 会导致黑屏?