title: Flutter: Firebase Phone Auth Not Authorized, but Google Sign In Successful
body: <p>I try to implement various Firebase Auth method in my Flutter app, when i try to implement Firebase Phone Auth (firebase_auth), it says this error:</p>
  
  <blockquote>
    <p>This app is not authorized to use Firebase Authentication. Please verify that the correct package name and SHA-1 are configured in the Firebase Console.</p>
  </blockquote>
  
  <p>My package name is already configured, when i setup my android app Firebase project, it connects successfully.</p>
  
  <p>Regarding the SHA-1 key, I already configured my Firebase Console to include both my debug key and my release key, i get debug key from: <code>keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore</code> also i try with my release key, and build my apk in release version.</p>
  
  <p>I also re-download google-service.json and running <code>flutter clean</code> to ensure everything is clean.</p>
  
  <p>I also confirm that i run the application in real physical device, not emulator. But Until this point, i have no luck, still stuck (at least 2 days) in above error.</p>
  
  <p>The strange thing is, when i try to login using Google Sign-In, which also (AFAIK) require correct SHA-1 information, it is works successfully. But, i have no luck in Firebase Phone Auth.</p>
  
  <p>Many question and answer only address problem about running Firebase Phone in Emulator, or in unconfigured SHA-1 Firebase Console, or wrong debug/release key, or cleaning the project. But in my case, i haven't found any answer for my problem.</p>
  
  <p>For reference, this is my Sign In with Phone Number dart code (which i get from firebase_auth/example github repo):</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  
  final FirebaseAuth _auth = FirebaseAuth.instance;
  
  class SignInPage extends StatefulWidget {
    final String title = 'Registration';
    @override
    State&lt;StatefulWidget&gt; createState() =&gt; SignInPageState();
  }
  
  class SignInPageState extends State&lt;SignInPage&gt; {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          actions: &lt;Widget&gt;[
            Builder(builder: (BuildContext context) {
              return FlatButton(
                child: const Text('Sign out'),
                textColor: Theme.of(context).buttonColor,
                onPressed: () async {
                  final FirebaseUser user = await _auth.currentUser();
                  if (user == null) {
                    Scaffold.of(context).showSnackBar(const SnackBar(
                      content: Text('No one has signed in.'),
                    ));
                    return;
                  }
                  _signOut();
                  final String uid = user.uid;
                  Scaffold.of(context).showSnackBar(SnackBar(
                    content: Text(uid + ' has successfully signed out.'),
                  ));
                },
              );
            })
          ],
        ),
        body: Builder(builder: (BuildContext context) {
          return ListView(
            scrollDirection: Axis.vertical,
            children: &lt;Widget&gt;[
              _PhoneSignInSection(Scaffold.of(context))
            ],
          );
        }),
      );
    }
  
    // Example code for sign out.
    void _signOut() async {
      await _auth.signOut();
    }
  }
  
  class _PhoneSignInSection extends StatefulWidget {
    _PhoneSignInSection(this._scaffold);
  
    final ScaffoldState _scaffold;
    @override
    State&lt;StatefulWidget&gt; createState() =&gt; _PhoneSignInSectionState();
  }
  
  class _PhoneSignInSectionState extends State&lt;_PhoneSignInSection&gt; {
    final TextEditingController _phoneNumberController = TextEditingController();
    final TextEditingController _smsController = TextEditingController();
  
    String _message = '';
    String _verificationId;
  
    @override
    Widget build(BuildContext context) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: &lt;Widget&gt;[
          Container(
            child: const Text('Test sign in with phone number'),
            padding: const EdgeInsets.all(16),
            alignment: Alignment.center,
          ),
          TextFormField(
            controller: _phoneNumberController,
            decoration: const InputDecoration(
                labelText: 'Phone number (+x xxx-xxx-xxxx)'),
            validator: (String value) {
              if (value.isEmpty) {
                return 'Phone number (+x xxx-xxx-xxxx)';
              }
              return null;
            },
          ),
          Container(
            padding: const EdgeInsets.symmetric(vertical: 16.0),
            alignment: Alignment.center,
            child: RaisedButton(
              onPressed: () async {
                _verifyPhoneNumber();
              },
              child: const Text('Verify phone number'),
            ),
          ),
          TextField(
            controller: _smsController,
            decoration: const InputDecoration(labelText: 'Verification code'),
          ),
          Container(
            padding: const EdgeInsets.symmetric(vertical: 16.0),
            alignment: Alignment.center,
            child: RaisedButton(
              onPressed: () async {
                _signInWithPhoneNumber();
              },
              child: const Text('Sign in with phone number'),
            ),
          ),
          Container(
            alignment: Alignment.center,
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Text(
              _message,
              style: TextStyle(color: Colors.red),
            ),
          )
        ],
      );
    }
  
    // Example code of how to verify phone number
    void _verifyPhoneNumber() async {
      setState(() {
        _message = '';
      });
      final PhoneVerificationCompleted verificationCompleted =
          (AuthCredential phoneAuthCredential) {
        _auth.signInWithCredential(phoneAuthCredential);
        setState(() {
          _message = 'Received phone auth credential: $phoneAuthCredential';
        });
      };
  
      final PhoneVerificationFailed verificationFailed =
          (AuthException authException) {
        setState(() {
          _message =
          'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}';
        });
      };
  
      final PhoneCodeSent codeSent =
          (String verificationId, [int forceResendingToken]) async {
        widget._scaffold.showSnackBar(const SnackBar(
          content: Text('Please check your phone for the verification code.'),
        ));
        _verificationId = verificationId;
      };
  
      final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
          (String verificationId) {
        _verificationId = verificationId;
      };
  
      await _auth.verifyPhoneNumber(
          phoneNumber: _phoneNumberController.text,
          timeout: const Duration(seconds: 60),
          verificationCompleted: verificationCompleted,
          verificationFailed: verificationFailed,
          codeSent: codeSent,
          codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
    }
  
    // Example code of how to sign in with phone.
    void _signInWithPhoneNumber() async {
      final AuthCredential credential = PhoneAuthProvider.getCredential(
        verificationId: _verificationId,
        smsCode: _smsController.text,
      );
      final FirebaseUser user =
          (await _auth.signInWithCredential(credential)).user;
      final FirebaseUser currentUser = await _auth.currentUser();
      assert(user.uid == currentUser.uid);
      setState(() {
        if (user != null) {
          _message = 'Successfully signed in, uid: ' + user.uid;
        } else {
          _message = 'Sign in failed';
        }
      });
    }
  }
  </code></pre>
  
  <p>Thanks for your response, before and after.</p>