gpt4 book ai didi

cordova - Ionic 4 oauth 重定向连接被拒绝

转载 作者:行者123 更新时间:2023-12-04 14:20:46 30 4
gpt4 key购买 nike

我正在使用 ionic/cordova 构建一个 Android 和 iOS 应用程序:ionic 版本是:4.11.0 & Cordova 版本是:8.1.2

我创建了该应用程序并在 chrome 浏览器中进行了测试,整个应用程序运行良好,包括授权、获取数据等。

当我创建要测试的 Android 应用程序时,我的问题就开始了。无论我做什么,我都无法获得重定向到应用程序的授权工作流程。

这是我尝试过的:

1- 无论我在 config.xml、cordova web View 插件和 cordova 自定义 url 方案插件中尝试什么,回调“http/localhost”都会拒绝连接。

2- 回调“myapp://callback”给出了 err_unkown_url_schema”,无论我尝试修改 config.xml 并使用上面相同的 cordova 插件。

我正在 LGG6 Android 版本 8.0.0 上进行测试。尚未在 iOS 上进行测试。

代码片段:

var uniqueWindowId = 'authorization-' + this.client_id
var params = 'titlebar=no, location=yes'
var loginWindow = window.open(this.authCodeURL, uniqueWindowId, params);

loginWindow.addEventListener(
'message',
e => {
var oauthMessage = e.data;
alert(oauthMessage);
loginWindow.close();
loginWindow.opener.postMessage(oauthMessage, 'https://localhost/');
},
false
);

这是通过 Android Studio 来自设备的日志

Connecting to io.ionic.starter
Connected to the target VM, address: 'localhost:8600', transport: 'socket'
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/zygote64: Late-enabling -Xcheck:jni
W/ActivityThread: Application io.ionic.starter is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/zygote64: Debugger is active
I/System.out: Debugger has connected
waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1419)
I/InstantRun: starting instant run server: is main process
I/CordovaLog: Changing log level to DEBUG(3)
I/CordovaActivity: Apache Cordova native platform version 7.1.4 is starting
D/CordovaActivity: CordovaActivity.onCreate()
I/WebViewFactory: Loading com.android.chrome version 72.0.3626.121 (code 362612152)
I/cr_LibraryLoader: Time to load native libraries: 7 ms (timestamps 8989-8996)
I/chromium: [INFO:library_loader_hooks.cc(42)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_LibraryLoader: Expected native library version number "72.0.3626.121", actual native library version number "72.0.3626.121"
W/cr_ChildProcLH: Create a new ChildConnectionAllocator with package name = com.android.chrome, sandboxed = true
I/cr_BrowserStartup: Initializing chromium process, singleProcess=false
W/ResourceType: Failure getting entry for 0x7f120538 (t=17 e=1336) (error -2147483647)
D/IonicWebViewEngine: Ionic Web View Engine Starting Right Up 1...
D/PhoneWindow: windowLightStatusBar : false, disable View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
D/SystemWebViewEngine: CordovaWebView is running on device made by: LGE
D/PluginManager: init()
D/PhoneWindow: windowLightStatusBar : false, disable View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
D/OpenGLRenderer: HWUI GL Pipeline
D/BezellessGripSuppressionFilter: getdisplaysize, x : 1440 y : 2880
D/PhoneWindow: windowLightStatusBar : false, disable View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
I/zygote64: Do partial code cache collection, code=28KB, data=25KB
I/zygote64: After code cache collection, code=27KB, data=25KB
Increasing code cache capacity to 128KB
D/BezellessGripSuppressionFilter: getdisplaysize, x : 1440 y : 2880
D/CordovaWebViewImpl: >>> loadUrl(file:///android_asset/www/index.html)
I/AudioManagerEx: AudioManagerEx created
W/cr_media: Requires BLUETOOTH permission
D/CordovaActivity: Started the activity.
I/Adreno: QUALCOMM build : 14c0496, Ida6448821d
Build Date : 01/08/18
OpenGL ES Shader Compiler Version: EV031.22.00.01
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.6.5.R1.08.00.00.312.043
Remote Branch : NONE
Reconstruct Branch : NOTHING
D/CordovaActivity: Resumed the activity.
I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
D/BezellessGripSuppressionFilter: getdisplaysize, x : 1440 y : 2880
I/Adreno: PFP: 0x005ff087, ME: 0x005ff063
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 2
W/AudioCapabilities: Unsupported mime audio/x-lg-alac
W/AudioCapabilities: Unsupported mime audio/x-lg-flac
W/AudioCapabilities: Unsupported mime audio/adpcm
W/AudioCapabilities: Unsupported mime audio/g726
W/AudioCapabilities: Unsupported mime audio/lg-wma-voice
W/AudioCapabilities: Unsupported mime audio/x-lg-ms-wma
W/VideoCapabilities: Unsupported mime video/mjpg
W/VideoCapabilities: Unsupported mime video/theora
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
Unrecognized profile 2130706434 for video/avc
I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
Unrecognized profile 2130706434 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@fdd775d time:801221046
W/VideoCapabilities: Unsupported mime video/dolby-vision
W/VideoCapabilities: Unsupported mime video/dolby-vision
W/VideoCapabilities: Unsupported mime video/mp4v-esdp
I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
W/cr_CrashFileManager: /data/user/0/io.ionic.starter/cache/WebView/Crash Reports does not exist or is not a directory
D/CordovaWebViewImpl: onPageDidNavigate(file:///android_asset/www/index.html)
D/CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html)
D/SERVER: Handling local request: http://localhost/
D/CordovaWebViewImpl: onPageDidNavigate(http://localhost/)
D/SERVER: Handling local request: http://localhost/cordova.js
D/SERVER: Handling local request: http://localhost/build/main.css
D/SERVER: Handling local request: http://localhost/build/polyfills.js
D/SERVER: Handling local request: http://localhost/build/vendor.js
D/SERVER: Handling local request: http://localhost/build/main.js
D/JsMessageQueue: Set native->JS mode to EvalBridgeMode
D/SERVER: Handling local request: http://localhost/cordova_plugins.js
D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-device/www/device.js
D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-inappbrowser/www/inappbrowser.js
D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-ionic-keyboard/www/android/keyboard.js
D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-ionic-webview/src/www/util.js
D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-splashscreen/www/splashscreen.js
I/zygote64: Do partial code cache collection, code=61KB, data=56KB
After code cache collection, code=61KB, data=56KB
Increasing code cache capacity to 256KB
D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-statusbar/www/statusbar.js
D/SERVER: Handling local request: http://localhost/plugins/cordova-sqlite-storage/www/SQLitePlugin.js
D/SystemWebChromeClient: http://localhost/build/vendor.js: Line 4325 : Angular is running in the development mode. Call enableProdMode() to enable the production mode.
I/chromium: [INFO:CONSOLE(4325)] "Angular is running in the development mode. Call enableProdMode() to enable the production mode.", source: http://localhost/build/vendor.js (4325)
D/SystemWebChromeClient: http://localhost/build/main.js: Line 998 : ################################################################################ home.ts constructor
I/chromium: [INFO:CONSOLE(998)] "################################################################################ home.ts constructor", source: http://localhost/build/main.js (998)
D/SERVER: Handling local request: http://localhost/assets/icon/icon.png
D/SERVER: Handling local request: http://localhost/assets/fonts/ionicons.woff2?v=3.0.0-alpha.3
D/SERVER: Handling local request: http://localhost/assets/fonts/roboto-medium.woff2
D/SERVER: Handling local request: http://localhost/assets/fonts/roboto-regular.woff2
D/SystemWebChromeClient: http://localhost/build/vendor.js: Line 140284 : Ionic Native: deviceready event fired after 1716 ms
I/chromium: [INFO:CONSOLE(140284)] "Ionic Native: deviceready event fired after 1716 ms", source: http://localhost/build/vendor.js (140284)
I/App: WARNING: Back Button Default Behavior will be overridden. The backbutton event will be fired!
D/CordovaWebViewImpl: onPageFinished(http://localhost/)
D/SERVER: Handling local request: http://localhost/assets/icon/favicon.ico
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/zygote64: Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()
I/zygote64: Do full code cache collection, code=123KB, data=107KB
I/zygote64: After code cache collection, code=94KB, data=64KB
D/InAppBrowser: target = _self
D/InAppBrowser: in self
D/InAppBrowser: isUrlWhiteListed [class java.lang.String]
D/InAppBrowser: loading in InAppBrowser
D/PhoneWindow: windowLightStatusBar : false, disable View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
D/BezellessGripSuppressionFilter: getdisplaysize, x : 1440 y : 2880
I/zygote64: Do partial code cache collection, code=118KB, data=94KB
After code cache collection, code=118KB, data=94KB
Increasing code cache capacity to 512KB
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
I/AssistStructure: Flattened final assist data: 520 bytes, containing 1 windows, 2 views
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP

我在屏幕上得到的消息是:

the webpage at http://localhost/?code=......@state=..... could nopt be loaded becuase:

net::ERR_CONNECTION_REFUSED

最佳答案

如果您通过应用程序外部的 url 进行 oauth,我建议使用 inappbrowser ionic native 插件。

https://ionicframework.com/docs/native/in-app-browser/

你试过吗?一般来说,这种使用 inapp 浏览器作为 oauth 的方法正在成为一种反模式,随着 Ionic Capacitor 的发展,他们没有使用 inappbrowser,而是围绕适用于 iOS 的 SafariViewController 和适用于 Android 的 Chrome 自定义选项卡实现了一个解决方案,但这仍然非常在我看来,很多都处于测试阶段。

https://capacitor.ionicframework.com/docs/apis/browser/

这是一篇关于使用 inappbrowser 的 OAuth 的过时文章,但它很好地涵盖了插件的基本使用:

https://www.thepolyglotdeveloper.com/2016/01/using-an-oauth-2-0-service-within-an-ionic-2-mobile-app/

关于它为何成为反模式的文章: https://medium.com/@jlchereau/stop-using-inappbrowser-for-your-cordova-phonegap-oauth-flow-a806b61a2dc5

就您的具体问题而言,我也会检查控制台日志,并确保这不是 CORS 问题,还要检查您的白名单以在 config.xml 中进行导航。

关于cordova - Ionic 4 oauth 重定向连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55112231/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com