- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 AuthSession 将我的登录设置为我的 React native Expo 应用程序。
我不断收到此错误:ValidationError: child "authUrl"fails because ["authUrl"must be a valid 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'
UPDATE 另外,一定要在你的 app.json 中直接在 'expo' 下添加一个方案,该方案应该是你的 slug 名称全部小写,不要忘记它必须是全部小写。另外,不要忘记这个新的 app.json 不能通过 OTA 更新,必须提交到应用商店。如果您尝试在没有包含该方案的更新的 app.json 的情况下使用此 Auth0,那么您将收到一个 Safari 错误,提示“Safari 无法打开此页面,因为它是无效的 URL”或类似的内容。当您看到此消息时,请记住这不是您的重定向 URL 的问题(假设您使用的是样板 AuthSession.getRedirectURL() 方法,并且您将相同的重定向 URL 放入 Auth0 设置的回调中)。如果您执行了这两件事,那么您会看到此错误,因为您尚未在应用商店或测试飞行构建中更新您的方案。
关于React-Native Expo 应用程序 Auth0 登录,AuthSession - authURL 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57877972/
我正在尝试使用 AuthSession 将我的登录设置为我的 React native Expo 应用程序。 我不断收到此错误:ValidationError: child "authUrl"fail
如何从服务或测试中的 Grails 中的 Dropbox authUrl 获取访问代码?在 Grails Dropbox wiki有以下内容: Next user will need to redir
我是一名优秀的程序员,十分优秀!