提供的身份验证凭证格式错误或已过期.-Flutter Facebook登录 [英] The supplied auth credential is malformed or has expired. - Flutter Facebook Login

查看:210
本文介绍了提供的身份验证凭证格式错误或已过期.-Flutter Facebook登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Firebase实时数据库在我的flutter应用程序中实现FacebookLogin.我可以登录到我的应用程序.但是,当我尝试使用FB的auth令牌从数据库中获取某些内容时,出现以下错误:

I am trying to implement FacebookLogin in my flutter app using Firebase Realtime Database. I am able to login to my app. However, when I try to fetch something from the Database using the FB's auth token, I get the following error:

 E/flutter (30549): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [firebase_auth/invalid-credential] The supplied auth credential is malformed or has expired. [ Unsuccessful debug_token response from Facebook: {"error":{"message":"Invalid OAuth access token signature.","type":"OAuthException","code":190,"fbtrace_id":"AwuVQUt6tCG1go"}} ]

这是我的Facebook登录代码:

Here's my facebook login code:

Future signInFB() async {
      var facebookLogin = FacebookLogin();
    var facebookLoginResult =
        await facebookLogin.logIn(['email']);
     switch (facebookLoginResult.status) {
      case FacebookLoginStatus.error:
        break;
      case FacebookLoginStatus.cancelledByUser:
        print("CancelledByUser");           
        break;
      case FacebookLoginStatus.loggedIn:
        print("LoggedIn");
        var graphResponse = await http.get(
            'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email,picture.height(200)&access_token=${facebookLoginResult
                .accessToken.token}');
          fbToken = facebookLoginResult.accessToken.token.toString();
    var profile = json.decode(graphResponse.body);
    final FirebaseAuth _auth = FirebaseAuth.instance;
    print('Token is ' + fbToken); 
    final OAuthCredential credential =  FacebookAuthProvider.credential(fbToken); 
    final User user = (await _auth.signInWithCredential(credential)).user;
    assert(!user.isAnonymous);
    assert(await user.getIdToken() != null);
     _token = await user.getIdToken();
     _userId = user.uid;
    print('Profile is ' + profile.toString());
    break;
  }
  }

推荐答案

我认为您在Facebook应用中的密钥哈希格式不正确.Facebook应用程序需要使用Base64密钥哈希才能工作.您必须将Android密钥库中的SHA1指纹编码为Base64.

I think your key hashes in facebook app is malformed. Facebook app needs Base64 key hashes to work. You have to encode your SHA1 fingerprint from android keystore to Base64.

要做到这一点,只需在浏览器控制台中运行以下javascript代码行

To do that simply run this line of javascript code in browser console

btoa('your SHA1 key here'.split(':').map(hc => String.fromCharCode(parseInt(hc, 16))).join(''))

将您收到的输出粘贴到设置>中的关键哈希值.开发人员Facebook

Paste the output you receive to key hashes in setting > basic panel of your facebook app on Facebook for Developers

这篇关于提供的身份验证凭证格式错误或已过期.-Flutter Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆