【问题标题】:How to implement LinkedIn auth with Firebase?如何使用 Firebase 实现 LinkedIn 身份验证?
【发布时间】:2017-12-29 13:37:58
【问题描述】:

我的 Ionic 应用程序有不同的身份验证方式,包括 Google, LinkedIn ,现在 firebase 不支持 linkedIn 开箱即用,但似乎有一种方法可以使用自定义身份验证和使用 @987654325 @,

谁能给我一些关于它的1、2、3、4指令?

【问题讨论】:

标签: firebase ionic-framework ionic2 firebase-authentication linkedin


【解决方案1】:

这个问题看起来很有趣。我也在研究。我提供了一些有用的链接。

https://jwt.io/ -- 您可以在此处找到适用于 Android 的第三方 JWT 库。因为 Firebase 使用基于 SON Web 令牌 (JWT) 的身份验证。

https://firebase.google.com/docs/auth/admin/verify-id-tokens#verify_id_tokens_using_a_third-party_jwt_library

我们无法在 Firebase Admin SDK 中创建自定义令牌。但我们可以从 Firebase 身份验证服务器创建自定义令牌。说明在这里:https://firebase.google.com/docs/auth/admin/create-custom-tokens

String uid = "some-uid";
HashMap<String, Object> additionalClaims = new HashMap<String, Object>();
additionalClaims.put("premiumAccount", true);

FirebaseAuth.getInstance().createCustomToken(uid, additionalClaims)
    .addOnSuccessListener(new OnSuccessListener<String>() {
        @Override
        public void onSuccess(String customToken) {
            // Send token back to client
/* Here, you get the custom token. You can simply store this token in String variable, and later pass as customToken */
        }
    });

此链接“https://github.com/jwtk/jjwt”提供用于创建自定义 JWT 令牌的 API。创建自定义令牌后,您可以使用

FirebaseAuth.getInstance().signInWithCustomToken(mCustomToken)
        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    // Sign in success, update UI with the signed-in user's information
                    Log.d(TAG, "signInWithCustomToken:success");
                    FirebaseUser user = mAuth.getCurrentUser();
                    updateUI(user);
                } else {
                    // If sign in fails, display a message to the user.
                    Log.w(TAG, "signInWithCustomToken:failure", task.getException());
                    Toast.makeText(CustomAuthActivity.this, "Authentication failed.",
                            Toast.LENGTH_SHORT).show();
                    updateUI(null);
                }
            }
        });

注意:我之前没有实现过这个。我是对此非常感兴趣的人之一。当你完全解决这个问题时,我会按照你的回答。

【讨论】:

    【解决方案2】:

    我能够使用用于 LinkedIn 身份验证的 firebase 函数使用令牌进行身份验证和登录。这还没有投入生产。这是用于 LinkedIn 身份验证的 GitHub 存储库的链接。

    https://github.com/firebase/functions-samples/tree/master/linkedin-auth

    【讨论】:

      猜你喜欢
      • 2017-11-29
      • 2019-03-25
      • 2015-06-29
      • 1970-01-01
      • 2019-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多