Is there any twitter authentication for flutter web? - flutter

so I want users to be able to sign up with their twitter account on my flutter website.
I've found this package (https://pub.dev/packages/flutter_twitter) but I've tried it and it does not work on flutter web, only on mobiles.
So, do I have to make this auth myself? If so, how could i do that?

You can use firebase Authentication sign-in method with twitter

For Flutter Web, the flutter_twitter package does NOT work, unfortunately. However, using firebase_auth and firebase_core will work for Flutter Web:
Future<bool> signInWithTwitter() async {
final userCredential = await FirebaseAuth.instance
.signInWithPopup(TwitterAuthProvider());
return userCredential.user != null;
}
Before you can use that, you need to initialize Firebase for the App:
await Firebase.initializeApp();
Don't forget to listen to the user changes, for example:
FirebaseAuth.instance
.authStateChanges()
.listen((User? user) {
if (user == null) {
...
} else {
...
}
});
Also, make sure that you set the callback URL in Twitter's "Authentication settings" to something like:
https://[YOURAPPNAME].firebaseapp.com/__/auth/handler
and that your Firebase Authentications include Twitter as a provider.

you can use the Firebase Auth Plugin provided by the Firebase team.
This plugin support Google, Email and Password, Phone, Anonymously, GitHub, Facebook, and Twitter authentication.
Or you can use Flutter_Twitter package, TwitterAPI package provided by the community.
Hope it will help

Related

my flutter app doesn't open authentication link

I am using firebase authentication and facebook authentication to facilitate users auth.
But when I click the button for face book auth it stops loading and nothing happens.
and in the release mode the link doesn't open.
I have tried all youtube videos to make facebook auth work.
This is my source code:
Future<UserCredential> signInWithFacebook() async {
// Trigger the sign-in flow
final LoginResult loginResult = await FacebookAuth.instance.login();
// Create a credential from the access token
final OAuthCredential facebookAuthCredential =
FacebookAuthProvider.credential(loginResult.accessToken!.token);
// Once signed in, return the UserCredential
return _auth.signInWithCredential(facebookAuthCredential);
}
Facebook have already updated their api for signin options.
try reading this links it might help
ff:
[https://pub.dev/packages/flutter_facebook_auth]
[https://medium.com/flutter-community/flutter-facebook-login-77fcd187242]
![and also for the fb api i have use a webview to fetch it and send the request to the post]

How to sign a Azure AD user into Firebase in a Flutter mobile app?

For a Flutter mobile app I am trying to use a Microsoft OAuthProvider to get a Firebase credential with which to sign the user into Firebase with their Azure AD account.
The closest I got was using a third party Active Directory auth package to log the user in and get an access token. However the sign-in to Firebase fails with an error message that suggests the idToken is invalid.
final AadOAuth oauth = new AadOAuth(config);
await oauth.login();
// accessToken looks legit
String accessToken = await oauth.getAccessToken();
String idToken = await oauth.getIdToken();
OAuthProvider provider = OAuthProvider('microsoft.com');
// Also tried the constructor without the idToken
OAuthCredential credential = provider.credential(accessToken: accessToken, idToken: idToken);
// app fails here:
await FirebaseAuth.instance.signInWithCredential(credential);
// this works fine, but only on web platform:
await FirebaseAuth.instance.signInWithPopup(provider);
Because it is a platform specific error (iOS in this case), the exception details are not surfaced. All I get is:
PlatformException(internal-error, ) nativeErrorCode: 17999
Here is my app settings in the Azure portal:
Full manifest here
Has anyone been successful in using Microsoft Auth to sign a user in to Firebase in a Flutter mobile app?
You can use Firebase Auth OAuth package for it.
And sign in to the firebase using the Microsoft Auth provider.
User user = await FirebaseAuthOAuth().openSignInFlow(
"microsoft.com", ["email openid"], {'tenant': 'your-tenent-id'});
This integrates nicely with firebase so, firebase authStateChange also works with this method.
You have just to not receiving idToken, just verify that you have add the id_token for the response_type and also openid scope like
provider.addScope('openid');
Also check weather you have allowed implicit flow with id token in the Azure portal app settings (you sould check ID tokens on the Authentication tab under Implicit grant section).
Ok than have you added Microsoft as a authentication provider in the firebase authentication configuration Sign-in method page? And also have you tried to authenticate with Auth, after getCredentials method as stated in the documentation?
provider.getCredentialWith(nil) { credential, error in
if error != nil {
// Handle error.
}
if credential != nil {
Auth().signIn(with: credential) { authResult, error in
if error != nil {
// Handle error.
}
// User is signed in.
// IdP data available in authResult.additionalUserInfo.profile.
// OAuth access token can also be retrieved:
// authResult.credential.accessToken
// OAuth ID token can also be retrieved:
// authResult.credential.idToken
}
}
}
firebase authentication package has a method called signInWithPopup so you don't need firebase_auth_oauth anymore. here my code:
Future<UserCredential?> loginWithMicrosoft() async {
OAuthProvider provider = OAuthProvider('microsoft.com');
provider.setCustomParameters({
"tenant": "your-tenant-id",
});
provider.addScope('user.read');
provider.addScope('profile');
try {
final userCredential = await FirebaseAuth.instance.signInWithPopup(provider);
return userCredential;
} on FirebaseAuthException catch(err) {
debugPrint(err.message);
// Handle FirebaseAuthExceptions
// ex: firebase_auth/account-exists-with-different-credential
}
}
Remeber add the redirect URI and enable de scopes in Azure Portal.

How to show Oauth Consent screen in flutter

I am trying to user gmail api. Google is asking me to make a video with demo of Oauth consent screen.
While searching in the internet I have found solutions for web and native android android. The docs of flutter packages googleapi and googleapi_auth were not very helful. If anyone has already implemented any suggestions would be helpful.
It's probably too late but here is the code for
' clientViaUserConsent(_clientid, _scopes, userPrompt)
.then((AuthClient client) {
//your code to authenticate any of your google platform
}
Here is the userPrompt function
void userPrompt(String url) async {
if (await canLaunch(url)) {
print("Launching url");
launch(url);
} else {
print("unable to launch the url");
}}
So whenever the clientviauserprompt is called the prompt function will launch the url to the default browser for the user consent.
You have to use urllauncher dependency for this.

Flutter - How to link social account using Firebase facebook and google plugin

I have a flutter app and would like the user to authenticate both with FB and Google. I do not want multiple accounts, just a single account that links both.
I am using :
firebase_auth 0.15.1
google_sign_in 4.0.14
facebook_plugin 3.0.0
I am not able to get the email address of the user when the user's account already exist with a different provider. The email is needed in order to get the list of providers for that user using the API call "fetchSignInMethodsForEmail"
Here is an example:
1: User login with Google credentials. The account is created in firebase and google is linked.
2: The user now logoff
3: The user now tries to login with FB with the same email.
-- User get the following error
code:"ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL"
details: null
message: "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address., **null**))
As you can see the email is null. I need the email in order to get a list of providers. Then I can redirect the user to correct provider
here is a snippet of my code
Future<FirebaseUser> signInWithFacebook({bool isIos}) async {
AuthCredential credential;
try {
final FacebookLoginResult result = await facebookLogin.logIn(['email']);
if (result.accessToken != null) {
credential = FacebookAuthProvider.getCredential(
accessToken: result.accessToken.token
);
AuthResult authResult = await _firebaseAuth.signInWithCredential(
credential,
);
firebaseUser = authResult.user;
return firebaseUser;
} catch (e) {
throw Exception(e);
}
return null;
}
Thanks for your help

Selecting Email Account from google_sign_in during Flutter integration testing

I was trying to test sign-in to my home screen for my flutter app. I am using the google-signin ( https://pub.dev/packages/google_sign_in) package from Flutter to perform login and authentication. So once the login button is pressed, a popup appears asking the user to select the user account. At that point, I am unable to control the tap as this dialog screen is generated by the plugin. How do I implement selection of the user account in this case ?
test('Test Login', () async {
final Timeline timeline = await driver.traceAction(() async {
await driver.tap(find.byValueKey('GoogleLogin'));
await driver.tap(find.text('myemail#gmail.com')); // This will not work !!!
});
TimelineSummary.summarize(timeline)
..writeSummaryToFile('home_scroll_perf', pretty: true)
..writeTimelineToFile('home_scroll_perf', pretty: true);
});
In my opinion, this could be a problem when testing with any third party plugin. Please help.
It seems that the issue is still existing. There is no available workaround yet. Keep an eye on this GitHub post as this is closely monitored by the Flutter team.
Try Patrol, it lets you very easily interact with native UIs such as the Google sign-in dialog.
Below is a rough example of how I'd approach this. I'm going to assume that you're already signed in to a Google account, so the only thing you have to do is to select an email from the dialog.
// integration_test/sign_in_test.dart
void main() {
patrolTest(
'signs in with Google',
nativeAutomation: true,
(PatrolTester $) async {
await $.pumpWidgeAndSettle(YourAppWidget());
await $('Sign in with Google').tap();
await $.native.tap(Selector(text: 'your.email#gmail.com'));
await $.pumpAndSettle();
// should be signed in now
},
);
}
Remember: that integration tests has to be run with patrol drive, not flutter test integration_test.