React native 反应本机Expo应用程序Auth0登录,AuthSession-authURL失败

React native 反应本机Expo应用程序Auth0登录,AuthSession-authURL失败,react-native,authentication,expo,auth0,React Native,Authentication,Expo,Auth0,我正在尝试使用AuthSession设置登录我的react native Expo应用程序 我一直收到以下错误:ValidationError:child“authUrl”失败,因为[“authUrl”必须是有效的uri]” 奇怪的是,如果我在控制台上记录要传递的URI,复制它,并将其粘贴到浏览器中,它就可以工作了!(如预期的那样调出Auth0登录屏幕) 为什么我在尝试从Expo客户端应用程序调用时出现此错误 这是我的密码: function toQueryString(params) {

我正在尝试使用AuthSession设置登录我的react native Expo应用程序

我一直收到以下错误:ValidationError:child“authUrl”失败,因为[“authUrl”必须是有效的uri]”

奇怪的是,如果我在控制台上记录要传递的URI,复制它,并将其粘贴到浏览器中,它就可以工作了!(如预期的那样调出Auth0登录屏幕)

为什么我在尝试从Expo客户端应用程序调用时出现此错误

这是我的密码:

 function toQueryString(params) {
  return '?' + Object.entries(params)
    .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
    .join('&');
}

class SignInScreen extends React.Component {

logIn = async () => {
  const redirectUrl = AuthSession.getRedirectUrl();
  console.log(`Redirect URL: ${redirectUrl}`);

  // Structure the auth parameters and URL
  const queryParams = toQueryString({
    client_id: auth0ClientId,
    redirect_uri: redirectUrl,
    response_type: 'id_token', // id_token will return a JWT token
    scope: 'openid profile', // retrieve the user's profile
    nonce: 'nonce', // ideally, this will be a random value
  });
  const authUrl = `${auth0Domain}/authorize` + queryParams;

  // Perform the authentication
  const response = await AuthSession.startAsync({ authUrl });
  console.log('Authentication response', response);

  if (response.type === 'success') {
    this.handleResponse(response.params);
  }
};

handleResponse = (response) => {
  if (response.error) {
    Alert('Authentication error', response.error_description || 'something went wrong');
    return;
  }

 console.log(response.id_token)
};

我在发布后很快就发现了这一点。以下是我为让它工作所做的

我使用的是:

 const auth0Domain = 'myapp.auth0.com'
我应该使用:

const auth0Domain = 'https://myapp.auth0.com'
更新此外,请确保在app.json的“expo”下直接添加一个方案,该方案应为您的slug名称,全部小写,不要忘记必须全部小写。此外,不要忘记,此新app.json无法通过OTA更新,必须提交到app store。如果您尝试在不更新的情况下使用此Auth0d app.json包含该方案,则会出现safari错误,例如“safari无法打开此页面,因为它是无效url”或类似内容。当您看到此错误时,请记住这不是重定向url的问题(假设您使用的是样板文件AuthSession.getRedirectURL()方法,并将相同的重定向url放入Auth0设置中的回调中)。如果您执行了这两项操作,则会看到此错误,因为您尚未在应用商店或试飞生成中更新方案