MacOS 10.15(Catalina)中的ASWebAuthenticationSession [英] ASWebAuthenticationSession in MacOS 10.15 (Catalina)

查看:104
本文介绍了MacOS 10.15(Catalina)中的ASWebAuthenticationSession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 MacOS 10.15 中实现新的 ASWebAuthenticationSession,但我对 callbackURLScheme 有点困惑.

I am trying to implement the new ASWebAuthenticationSession in MacOS 10.15 and I'm getting a bit confused about the callbackURLScheme.

ASWebAuthenticationSession 的头文件说:

回调URL通常具有自定义URL方案.对于应用程序接收回调URL,它需要注册自定义URL其Info.plist中的方案,或将方案设置为callbackURLScheme初始化程序中的参数.

The callback URL usually has a custom URL scheme. For the app to receive the callback URL, it needs to either register the custom URL scheme in its Info.plist, or set the scheme to callbackURLScheme argument in the initializer.

所以我这样初始化:

self.webAuthSession = [[ASWebAuthenticationSession alloc] initWithURL:self.authURL
                                                    callbackURLScheme:@"myurlscheme://"
                                                    completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) {

}];

我尝试访问的oauth提供程序不支持自定义URL方案,因此我将其设置为重定向到一个网址,该网址又重定向到我的URL方案.

The oauth provider I am trying to access, does not support custom URL schemes, so I have it set to redirect to a web address which in turn redirects to my URL Scheme.

因此,在MacOS应用程序中单击登录"后,Safari会显示一个窗口,允许我登录该服务.成功登录后,发生重定向,但是网页仅显示一个屏幕,显示

So, after clicking Login in my MacOS app, Safari presents a window that allows me to login to the service. After successfully logging in the redirect happens but the web page just goes to a screen saying

Safari无法打开指定的地址.

Safari can't open the specified address.

我可以看到地址是 myurlscheme://?code = 1234567890abcdefgetc ... ,这是正确的,但显然不是在调用 ASWebAuthenticationSession 回调.

I can see that the address is myurlscheme://?code=1234567890abcdefgetc... which is correct but it's obviously not calling the ASWebAuthenticationSession callback.

如果我将URL Scheme添加到plist,则safari窗口将显示一个提示,询问您是否要在我的应用程序中打开它.

If I add the URL Scheme to the plist, then the safari window shows a prompt asking if you want to open it in the my app.

我知道我可以从App Delegate的 application:openURLs:方法中获取代码,但这很奇怪,对用户而言没有必要的提示,也可以使ASWebAuth ... 野生动物园窗口打开.这应该全部通过回调自动完成.

I know I can then fetch the code from the App Delegate's application:openURLs: method, but this is fiddly, has an unnecessary prompt for the user to click, and also leaves the ASWebAuth... safari window open. This should all be automatic through the callback.

触发回调的唯一方法是关闭safari窗口,在这种情况下它会错误地回调.

The only way I get the callback to fire, is by closing the safari window in which case it calls back with error.

推荐答案

我刚刚回到这里再次尝试,它在MacOS 10.15.1 10.15上似乎运行良好.2测试版.

I have just returned to this to try again and it seems to be working fine on MacOS 10.15.1 and 10.15.2 beta.

我注意到 callbackURLScheme 参数不能包含://

I have noticed that the callbackURLScheme parameter must not include ://

我无法返回并在 10.15 上再次对其进行测试,但我现在很高兴使用此功能,假设 10.15 上的每个人都已更新为 10.15.1

I'm not able to go back and test it again on 10.15 but i'm happy to use this now assuming everyone on 10.15 would have updated to 10.15.1

这篇关于MacOS 10.15(Catalina)中的ASWebAuthenticationSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆