【发布时间】:2020-06-09 10:11:53
【问题描述】:
我正在尝试使用 ASWebAuthenticationSession 从Stripe's OAuth endpoint 获取身份验证代码 - 此事件发生在调用我的 Stripe 重定向 url 之后。
不幸的是,authSession 的完成处理程序没有使用回调 URL 进行回调。我需要这个 callbackURL 来查询授权码。我已经阅读了关于这个主题的不同文章,但我不明白为什么我的实现不能按照我期望的方式工作。
这是我的代码:
class CreateStripeConnectAccountController: UIViewController {
var authSession: ASWebAuthenticationSession!
override func viewDidLoad() {
super.viewDidLoad()
configureAuthSession()
}
private func configureAuthSession() {
let urlString = Constants.URLs.stripeConnectOAuth // Sample URL
guard let url = URL(string: urlString) else { return }
let callbackScheme = "myapp:auth"
authSession = ASWebAuthenticationSession(url: url, callbackURLScheme: callbackScheme, completionHandler: { (callbackURL, error) in
guard error == nil, let successURL = callbackURL else {
print("Nothing")
return
}
let oauthToken = NSURLComponents(string: (successURL.absoluteString))?.queryItems?.filter({$0.name == "code"}).first
print(successURL.absoluteString)
})
authSession.presentationContextProvider = self
authSession.start()
}
}
extension CreateStripeConnectAccountController: ASWebAuthenticationPresentationContextProviding {
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
self.view.window ?? ASPresentationAnchor()
}
}
【问题讨论】:
-
如果没有人回答这个问题,请考虑在他们的 Github 上发布这个问题(如果有的话)。
-
@Glenn 好主意
-
@uchennaaguocha 您是否为您的应用启用了通用深度链接?这里的替代方法是在 webviews 中完全处理 OAuth,然后让您的“redirect_url”页面手动链接回您的 iOS 应用程序此外,当您在 AuthContext 中完成 OAuth 流程时,您的应用程序会发生什么?预计会打开您在 Connect 设置中指定的重定向 url
-
@hmunoz 我最初的方法涉及 webview。我的用户将创建一个 Stripe Connect 帐户,一旦完成,就会调用重定向 url。它会将用户重定向回应用程序。本周早些时候,我的应用被拒绝,因为 Apple 弃用了 UIWebview API。所以,这就是我使用 ASWebAuthenticationSession 而不是 webview 的原因。
-
@uchennaaguocha 了解详情!我也在做同样的事情并且它正在工作。即 Stripe Connect 页面 -> 重定向 URL -> 该页面深层链接到我的 iOS 应用程序。您能否仔细检查您的 url 方案以及重定向页面重定向到的 url 方案?你现在也可以使用 WKWebView 代替 UIWebView
标签: ios swift oauth stripe-payments aswebauthenticationsession