【问题标题】:Firebase: How does it know what account my OAuth token is associated with?Firebase:它如何知道我的 OAuth 令牌与哪个帐户相关联?
【发布时间】:2017-03-08 06:27:53
【问题描述】:

我即将使用这个 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 是随机的,我怎么知道123abc 连接到我的firebase 帐户中的cool@example.com

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

【问题讨论】:

    标签: ios firebase oauth firebase-authentication


    【解决方案1】:

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

    【讨论】:

    • 所以我应该将withCallbackURL 设置为myserver.com/something 并在我的服务器上创建一个自定义令牌,然后在success 回调中,我应该向我的服务器发出另一个请求以获取这个自定义令牌使用 instagram 返回的 oauth_token?
    • 您需要使用 Firebase Admin SDK 或您自己在服务器端创建一个自定义的签名 JWT 令牌,并将其传递给您应用内的 FIRAuth.auth()?.signIn(withCustomToken: 。自定义 JWT 将包含用户的 uid(Instagram 或您内部的),这将唯一标识该用户到 Firebase(并允许您在不同平台之间进行交叉引用)。这个链接描述得很好:firebase.google.com/docs/auth/admin/create-custom-tokens
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-31
    • 2021-06-12
    • 1970-01-01
    • 2021-04-20
    相关资源
    最近更新 更多