自定义重定向URI到macOS应用程序不起作用

ASSeeger

重定向的目的

我正在开发与思科Webex Teams Api集成的应用程序。不幸的是,对于macOS,他们没有SDK(只有iOS的SDK),所以我试图通过“手动”方式对其Api进行身份验证。

因此,我使用的是自定义URL,该URL具有备份的客户ID来检索代码。呼叫此URL时,Cisco的常规登录过程开始,要求用户使用其用户名登录并输入密码。成功登录后,Cisco的服务器会为您提供一个URL,其中包含随后需要进行编码的代码。

我到目前为止所得到的

自定义网址

我的原型当前仅包含一个按钮,该按钮调用自定义URL进行身份验证。要获取此URL,我需要在此处注册与Cisco的集成:https : //developer.webex.com/my-apps

到目前为止,当我单击按钮时,WKWebView实例将接管我的自定义URL:

https://api.ciscospark.com/v1/authorize?client_id=<**personalClientId**>&response_type=code&redirect_uri=<**BundleIdentifier**>3A%2F%2Fredirect&scope=spark%3Aall%20spark%3Akms&state=set_state_here

重定向URI

因此,我的重定向uri当前是ch.appfros.webexoauthwokflowprototype:// redirect此重定向uri已在我的集成注册表中向Cisco注册。

我知道我必须将此重定向uri放入我的应用程序中,所以我这样做了,导致相应的info.plist部分如下所示:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>response</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>ch.appfros.webexoauthwokflowprototype://</string>
        </array>
    </dict>
</array>

准备 AppDelegate

据我目前所知,似乎还需要在我的中有一个附加函数AppDelegate来处理回调。对于cocoa,这似乎是func application(_ application: NSApplication, open urls: [URL])方法。

据我了解,我将不得不在那里处理所有重定向。AppDelegate目前看起来像这样:

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {



    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application)
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
    }

    func application(_ application: NSApplication, open urls: [URL]) {
        print("got answer")
    }

}

我遇到的问题

我的问题是,执行登录过程会导致出现消息 There is no application set to open the URL ch.appfros.webexoauthwokflowprototype://redirect?code=&state=loggedIn.

因此,Cisco端的身份验证过程成功完成,它为我的系统提供了URL-我的计算机不知道该如何处理...我什至可以看到我需要检索即将到来的URL中的访问的代码返回,我只是没有将它们包含在我的应用程序中才能继续...

我想念什么?

很明显,我在这里遗漏了一些关键的东西-我只是不知道它是什么,而且在线研究对我没有帮助。我可以在这里和那里找到点点滴滴,但是我仍然要找到一个简明的说明,说明我该如何为macOS应用程序做些什么。

环境

  • Xcode 10.1
  • 斯威夫特4.2
  • 可可应用
  • 思科Webex Teams与身份验证URL的集成

编辑:更改为AppDelegate

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {



    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application)
         NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(self.handleAppleEvent(event:replyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
    }

    func application(_ application: NSApplication, open urls: [URL]) {
        print("got answer")
    }

    @objc
    func handleAppleEvent(event: NSAppleEventDescriptor, replyEvent: NSAppleEventDescriptor) {
        print("got answer in event handler")
    }

}

编辑2:更新至AppDelegate(以反映NoHalfBits的提示和技巧)

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {



    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application)

    }

    func applicationWillFinishLaunching(_ notification: Notification) {
        NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(self.handleAppleEvent(event:replyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
    }

    func application(_ application: NSApplication, open urls: [URL]) {
        print("got answer")
    }

    @objc
    func handleAppleEvent(event: NSAppleEventDescriptor, replyEvent: NSAppleEventDescriptor) {
        print("got answer in event handler")
    }

}
ASSeeger

事实证明,沙盒确实是问题所在。禁用沙箱功能后-我的公司将成为内部帮助的小助手,没什么花哨的东西,对于任何商店来说肯定没有任何东西-它立即起作用。

如果需要的话,我将不得不研究NSAppTransportSecurity实现的方式-感谢@NoHalfBits将我推向正确的方向。

所以现在我有

  • 注册的自定义网址
  • 应用沙箱已禁用
  • func application(_ application: NSApplication, open urls: [URL]) 在我的AppDelegate中实现(事实证明,这确实足够了,就像@Aaron Raimist所说的那样

谢谢你的帮助; 希望这可以帮助其他人(或我未来的自我):-)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在.NET ASPX应用程序中使用ExecuteURL的自定义错误页面不起作用(重定向工作正常)

自定义mod重定向不起作用

从Github Pages重定向到自定义子域不起作用

Django:Login_required(重定向到自定义 login_url)不起作用

子级路由不起作用,应用程序重定向到404页面

重定向到另一个应用程序时,“打印”不起作用

在Spring Boot应用程序中重定向到自定义错误页面时出错

如何从HomePage(Page)重定向到您的自定义应用程序模型

Azure Web应用程序,自定义状态代码描述不起作用

Cordova iOS 应用程序:此处地图的自定义标记图标不起作用

使用自定义钩子重新渲染应用程序不起作用

ASP.NET Core自定义中间件重定向到操作不起作用

在Heroku Web应用程序上,如何从用户从.herokuapp.com重定向到自定义域?

如何使用Phalcon php Micro应用程序和自定义路由重定向到索引

当某些路由位于自定义组件内时,react 重定向不起作用

Tailwind 中自定义类的方括号表示法在 Nuxt 应用程序中不起作用

Ag-Grid中的自定义过滤器在Angular 10应用程序中不起作用

自定义对话框在适配器中不起作用,应用程序崩溃

使用HttpPost的Android应用程序自定义Web服务身份验证不起作用

在Windows上使用IIS迁移后,Zend应用程序重定向不起作用

当应用程序不在根目录中时,重定向不起作用

控制台重定向在应用程序关闭之前不起作用(Java)

重定向asp.net Web应用程序之前,警报不起作用

chrome 自定义标签不重定向回混合应用程序

如何在我的Microsoft Teams自定义应用程序中重定向到另一个页面?

如果设置了自定义会话路径,重定向后,Yii Flash消息将不起作用

自定义引导加载程序不起作用

自定义虚拟绑定处理程序不起作用

Laravel自定义WebSocket处理程序不起作用