首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对于Swift ios13,Firebase推特oAuth回调不起作用

对于Swift ios13,Firebase推特oAuth回调不起作用
EN

Stack Overflow用户
提问于 2020-01-05 06:31:53
回答 2查看 1.1K关注 0票数 3

我已经按照https://firebase.google.com/docs/auth/ios/twitter-login上的说明找到了Swift的T,我得到了网页弹出窗口来授权我在Twitter Dev上创建的应用程序,回调被调用,然后webview位于一个空页面上,名为about:blank。除了单击done按钮之外,什么也做不了,这将导致一个错误消息:“Domain=FIRAuthErrorDomain interaction in Code=17058 by the user”。回调地址正确。我使用Twitter Consumer API密钥作为进入Firebase控制台的密钥。

我遗漏了什么?

EN

回答 2

Stack Overflow用户

发布于 2020-09-25 04:49:41

对于那些仍然在回调工作中遇到问题的人,我设法解决了它。遗憾的是,您必须在库中编辑该方法(不是最好的方法,但仍然。Bug被报告给firebase团队)。该方法应该类似于下面的方法(您可以在名为FIROAuthProvider.m的文件的125行中找到它。我故意留下注释行,所以你可以看到这里的问题……希望对某些人有帮助:)

代码语言:javascript
复制
- (void)getCredentialWithUIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
                         completion:(nullable FIRAuthCredentialCallback)completion {
  if (![FIRAuthWebUtils isCallbackSchemeRegisteredForCustomURLScheme:self->_callbackScheme]) {
    [NSException raise:NSInternalInconsistencyException
                format:@"Please register custom URL scheme '%@' in the app's Info.plist file.",
                       self->_callbackScheme];
  }
//  __weak __typeof__(self) weakSelf = self;
//  __weak FIRAuth *weakAuth = _auth;
//  __weak NSString *weakProviderID = _providerID;
  dispatch_async(FIRAuthGlobalWorkQueue(), ^{
    FIRAuthCredentialCallback callbackOnMainThread =
        ^(FIRAuthCredential *_Nullable credential, NSError *_Nullable error) {
          if (completion) {
            dispatch_async(dispatch_get_main_queue(), ^{
              completion(credential, error);
            });
          }
        };
    NSString *eventID = [FIRAuthWebUtils randomStringWithLength:10];
    NSString *sessionID = [FIRAuthWebUtils randomStringWithLength:10];
//    __strong __typeof__(self) strongSelf = weakSelf;
    [self
        getHeadFulLiteURLWithEventID:eventID
                           sessionID:sessionID
                          completion:^(NSURL *_Nullable headfulLiteURL, NSError *_Nullable error) {
                            if (error) {
                              callbackOnMainThread(nil, error);
                              return;
                            }
                            FIRAuthURLCallbackMatcher callbackMatcher =
                                ^BOOL(NSURL *_Nullable callbackURL) {
                                  return [FIRAuthWebUtils
                                      isExpectedCallbackURL:callbackURL
                                                    eventID:eventID
                                                   authType:kAuthTypeSignInWithRedirect
                                             callbackScheme:self->_callbackScheme];
                                };
//                            __strong FIRAuth *strongAuth = weakAuth;
                            [_auth.authURLPresenter
                                     presentURL:headfulLiteURL
                                     UIDelegate:UIDelegate
                                callbackMatcher:callbackMatcher
                                     completion:^(NSURL *_Nullable callbackURL,
                                                  NSError *_Nullable error) {
                                       if (error) {
                                         callbackOnMainThread(nil, error);
                                         return;
                                       }
                                       NSString *OAuthResponseURLString =
                                           [self OAuthResponseForURL:callbackURL
                                                                     error:&error];
                                       if (error) {
                                         callbackOnMainThread(nil, error);
                                         return;
                                       }
                                       __strong NSString *strongProviderID = _providerID;
                                       FIROAuthCredential *credential = [[FIROAuthCredential alloc]
                                               initWithProviderID:strongProviderID
                                                        sessionID:sessionID
                                           OAuthResponseURLString:OAuthResponseURLString];
                                       callbackOnMainThread(credential, nil);
                                     }];
                          }];
  });
}
票数 5
EN

Stack Overflow用户

发布于 2020-02-03 05:43:54

好的,所以我解决了这个问题,但不完全确定现在是如何解决的。我相信这是因为回调没有被发出,因此没有被应用程序接收到。回调不是由于身份验证而引起的,我相信是因为我没有创建服务条款和隐私策略。因此,请确保您已经在Twitter开发页面中做到了这一点。

在twitter dev页面中,回调链接是:https://yourApp.firebaseapp.com/__/auth/handler当您启用twitter时,您将在firebase身份验证设置中找到此链接。

确保在info.plist LSApplicationQueriesSchemes中有一个数组: twitter twitterauth

在您的swift文件中:

代码语言:javascript
复制
var provider = OAuthProvider(providerID: "twitter.com")

您的按钮操作:

代码语言:javascript
复制
@IBAction func onCustonTwitterButtonPressed(_ sender: Any) {
    MyAppsCoreServicesScripts.logoutSocial() // My logout routine.
    provider.getCredentialWith(nil) { credential, error in
    if let error = error {
        MyAppsCoreServicesScripts.showError(prefix: "Twitter Login",error: error, showMsg: true)
        } else if credential != nil {
            self.firebaseLogin(credential!)            
        }
    }
}

祝好运!希望这对某些人有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59595425

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档