【发布时间】:2022-04-08 15:14:12
【问题描述】:
我尝试在我的 Rails 应用程序中创建一个使用 OAuth 登录的反应原生应用程序。
我有这个反应原生设置
const config = {
issuer: 'http://app.domain.tld',
clientId: '85bb84b9cb0528b1f64b7c77586507b3ca5e69b11abe36ae1e54e88a6150c21e',
clientSecret: '0d3c0713437e0028a121a0c2294cc9a72f4eb5609416935a2860e20f176c7855',
redirectUrl: 'com.domain://com.domain',
responseType: 'code',
scopes: [],
dangerouslyAllowInsecureHttpRequests: __DEV__,
// clientAuthMethod: 'post',
serviceConfiguration: {
authorizationEndpoint: 'http://app.domain.tld/oauth/authorize',
tokenEndpoint: 'http://app.domain.tld/oauth/token',
// revocationEndpoint: 'http://app.domain.tld/oauth/revoke'
},
additionalParameters: {
approval_prompt: 'force'
}
}
// use the client to make the auth request and receive the authState
try {
const result = await authorize(config)
// result includes accessToken, accessTokenExpirationDate and refreshToken
console.log('result', result)
} catch (error) {
console.log('error', error.message)
}
当我按下按钮登录我的应用程序时,我会看到一个浏览器窗口,我可以在其中登录我的 rails 应用程序并被重定向到 oauth 应用程序的授权页面。在我授权我的应用程序后,我被重定向到应用程序并显示“网络错误”消息。有了这条消息,我无法找出问题所在,也许任何人都可以帮助我。
在服务器日志中我可以看到:
Redirected to com.domain://com.domain?code=54f3b4c03ea3724522f9a7983e2ea1b9037336076cd52cb875f9654d5d79784a&state=8xmiicVcPKN980ZDZUwBnw
在调试器-ui 中我得到这个错误日志:
error Error: Network error
at createErrorFromErrorData (ReactNativeART.js:10)
at ActivityIndicator.js:72
at MessageQueue.__invokeCallback (ReactNativeART.js:472)
at blob:http://localhost:8081/1fccf34b-97b0-4c42-81fa-f0e1391a3ad3:2358
at MessageQueue.__guard (ReactNativeART.js:373)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:http://localhost:8081/1fccf34b-97b0-4c42-81fa-f0e1391a3ad3:2357)
at debuggerWorker.js:80
所以我认为有问题。该应用程序没有向服务器发出任何进一步请求以获取 access_token。怎么了?
【问题讨论】:
-
你解决了吗?
标签: ruby-on-rails react-native oauth oauth-2.0 doorkeeper