Firebase:它如何知道我的OAuth令牌与哪个帐户相关联?

时间:2016-10-26 02:57:56

标签: ios firebase oauth firebase-authentication

我即将使用此cocoapod构建一个使用OAuth 2.0的iPad应用:https://github.com/OAuthSwift/OAuthSwift。我正在浏览这个firebase教程(https://firebase.google.com/docs/auth/ios/custom-auth),但是,我有点困惑。

鉴于我有这段代码:

oauthswift = OAuth2Swift(
    consumerKey:    "********",
    consumerSecret: "********",
    authorizeUrl:   "https://api.instagram.com/oauth/authorize",
    responseType:   "token"
)
let handle = oauthswift.authorize(
    withCallbackURL: URL(string: "oauth-swift://oauth-callback/instagram")!,
    scope: "likes+comments", state:"INSTAGRAM",
    success: { credential, response, parameters in
      print(credential.oauth_token)
      FIRAuth.auth()?.signIn(withCustomToken: credential.oauth_token ?? "") { (user, error) in
        // ...
      }

    },
    failure: { error in
      print(error.localizedDescription)
    }
)

如果令牌是随机的并且每个设备不同,那么firebase如何知道该令牌与哪个帐户相关联?我不知道如何将该令牌与帐户相关联。就像我使用用户名cool@example.com和密码blah123登录Instagram并且oauth_token是123abc一样,我怎么知道123abc已连接到我的cool@example.com如果123abc是随机的,则为firebase帐户?

我觉得我误解了其中一个概念。

1 个答案:

答案 0 :(得分:1)

您需要使用Firebase SDK从Instagram访问令牌服务器端创建自定义令牌。然后,您需要通过客户端从服务器请求此信息,并使用响应中的令牌signIn withCustomToken: