简体   繁体   English

在 macOS 上使用 SwiftUI 的身份验证过程

[英]Authentication Process with SwiftUI on macOS

I want to authenticate my user with Spotify for a Spotify client in SwiftUI now I've come to the problem that it seems like Webkit doesn't work on macOS and now I have no clue how to authenticate my user via Safari (or some other Browser).我想在 SwiftUI 中使用 Spotify 客户端对我的用户进行身份验证,现在我遇到了 Webkit 似乎无法在 macOS 上运行的问题,现在我不知道如何通过 Safari(或其他一些)对我的用户进行身份验证浏览器)。

It would be really helpful if somebody could help me and maybe have a solution and an explanation for that solution.如果有人可以帮助我并且可能有解决方案和对该解决方案的解释,那将非常有帮助。

Thanks.谢谢。

Take a look at the ASWebAuthenticationSession class. This class simplifies logging into websites by creating a private browser window for people to log into a website.看看ASWebAuthenticationSession class。这个 class 通过创建一个私人浏览器 window 来简化登录网站的过程,供人们登录网站。 By using ASWebAuthenticationSession , you don't have to deal with WebKit.通过使用ASWebAuthenticationSession ,您不必处理 WebKit。

To use ASWebAuthenticationSession you must perform the following steps:要使用ASWebAuthenticationSession ,您必须执行以下步骤:

  • Create a custom URL type for your app to take you back to your app when someone finishes logging in.为您的应用创建自定义 URL 类型,以便在有人完成登录时将您带回您的应用。
  • Create a class for the login session that conforms to ASWebAuthenticationPresentationContextProviding .为符合 ASWebAuthenticationPresentationContextProviding 的登录 session 创建一个ASWebAuthenticationPresentationContextProviding
  • Add a presentation anchor for the login session.为登录名 session 添加演示锚点。
  • Create an instance of ASWebAuthenticationSession , supplying the URL of the site you want to log in, the URL to go to when the session finishes, and a completion handler with code to run when the session ends successfully.创建ASWebAuthenticationSession的一个实例,提供您要登录的站点的 URL,URL 到 go 到 session 完成时,以及一个完成处理程序,其中包含在 session 成功结束时运行的代码。

The following article has more details on working with ASWebAuthenticationSession :以下文章包含有关使用ASWebAuthenticationSession的更多详细信息:

Log in to Websites with ASWebAuthenticationSession 使用 ASWebAuthenticationSession 登录网站

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM