标签: aswebauthenticationsession

AsWebAuthenticationsession 是否支持通用链接?

我使用 AsWebAuthenticationsession 从另一个应用程序到我的应用程序进行身份验证。我打开 AsWebAuthenticationsession,它会重定向我的应用程序的通用链接。问题是当它重定向我的应用程序通用链接时,它要求打开 App Store。当它重定向时,我想关闭会话。但是 AsWebAuthenticationsession 只需要一个自定义的 URL Scheme。我如何安全地处理它(因为自定义 URL Schemes 不安全:RFC8252 7.1

ios oauth-2.0 swift ios-universal-links aswebauthenticationsession

9
推荐指数
1
解决办法
452
查看次数

如何使用 ASWebAuthenticationSession 获取授权码?

我正在尝试使用 ASWebAuthenticationSession 从Stripe 的 OAuth 端点获取身份验证代码 - 此事件在调用我的 Stripe 重定向 url 后发生。

不幸的是,authSession 的完成处理程序不会使用callbackURL 进行回调。我需要这个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
       } …
Run Code Online (Sandbox Code Playgroud)

oauth ios stripe-payments swift aswebauthenticationsession

8
推荐指数
1
解决办法
9743
查看次数

ASWebAuthenticationSession 只显示取消按钮

我正在验证我们的 Web 服务ASWebAuthenticationSession,出于某种原因,最终重定向后的唯一选项是Cancel。我之前有过这个工作,即使我确实按下了取消,回调 Url 也是通过完成处理程序发送的,我能够在那里解析令牌形式。但现在我得到了错误ASWebAuthenticationSessionErrorCodeCanceledLogin

如何ASWebAuthenticationSession显示“完成”按钮并使用回调 Url 完成处理程序?上次 iOS 更新中有什么变化或中断吗?

我如何创建会话

if (@available(iOS 12.0, *)) {
    self.session = [[ASWebAuthenticationSession alloc]
                    initWithURL:@"http://service.com"
                    callbackURLScheme:@"http://website.com"
                    completionHandler:_sessionHandler];
     [self.session start];
}
Run Code Online (Sandbox Code Playgroud)

完成处理程序

_sessionHandler = ^(NSURL * _Nullable callbackURL, NSError * _Nullable error) {
    NSLog(@"Callback Url: %@, Error: %@", callbackURL, error);
    if ( callbackURL != nil ) {
        __block NSString * token = [weakSelf webToken:@"token" fromUrl:callbackURL];
        weakSelf.completionHandler([weakSelf parseWebToken:token], error);
    }
    else
        weakSelf.completionHandler(nil, error);
};
Run Code Online (Sandbox Code Playgroud)

输出

回调 …

single-sign-on sfsafariviewcontroller sfauthenticationsession aswebauthenticationsession

5
推荐指数
0
解决办法
886
查看次数

向下滑动以关闭时 ASWebAuthenticationSessionError.canceledLogin 不会触发

我正在创建一个ASWebAuthenticationSession会话,并且在完成处理程序中,我有用户取消登录时的清理任务:

let session = ASWebAuthenticationSession(url: url, callbackURLScheme: redirectURI) { (callbackURL: URL?, error: Error?) in
    if case .ASWebAuthenticationSessionError.canceledLogin? = error {
        // clean up tasks
    }

    // proceed...
}
Run Code Online (Sandbox Code Playgroud)

在 iOS 13+ 中,用户可以向下滑动以关闭,但在这种情况下根本不会触发整个完成处理程序。我不想通过启用 isModalInPresentation 来禁用此手势。

有没有办法在这种情况下触发 ASWebAuthenticationSessionError.canceledLogin ,或者如何检测用户向下滑动以取消ASWebAuthenticationSession会话?

ios aswebauthenticationsession

5
推荐指数
1
解决办法
260
查看次数

使用 ASWebAuthenticationSession 时清除 cookie

如何在使用ASWebAuthenticationSession时清除cookie,场景就像,不同的用户可以使用同一个设备登录。如果用户已经在完成 SSO 的情况下使用它,则应用程序不会坚持为新用户提供 SSO。

所以需要清除cookies。

提前致谢。

cookies swift aswebauthenticationsession

2
推荐指数
1
解决办法
2478
查看次数