How to show Oauth Consent screen in flutter - 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.

Related

Create a button to open app from flutter web

I would like to create an app in Flutter. The web version contains a button that should open version of android or IOS app according user platform if mobile version of app was installed (like an app install or open banner).
How should I detect is app installed in web flutter?
update:
I tried below code using import 'package:universal_html/html.dart' pakage:
window.location.href = (defaultTargetPlatform ==
TargetPlatform.android)
? 'https://play.google.com/store/apps/details?id=com.amazon.mShop.android.shopping'
: 'https://apps.apple.com/us/app/amazon-shopping/id297606951';
But this just open the store. I'm looking for a solution to open app directly if it was installed.
If this is fine for you, you can use an URL launcher. This way it opens the App store or play store and the user can either download the App or open it.
For Example flutter has a package that does most of this work:
https://github.com/Purus/launch_review
LaunchReview.launch(androidAppId: "yourpackagename", iOSAppId: "appid");
You just need to pass your package name and on ios your app ID
You could also use an URL Launcher:
https://pub.dev/packages/url_launcher
The code would be similar to this:
_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
}
else {
throw 'Could not launch $url';
}
}
URL Example
try {
launch("market://details?id=" + appPackageName);
} on PlatformException catch(e) {
launch("https://play.google.com/store/apps/details?id=" + appPackageName);
} finally {
launch("https://play.google.com/store/apps/details?id=" + appPackageName);
}
Note this code needs to be adapted
Also see this tutorial for help: https://flutteragency.com/open-appstore-playstore-url-in-flutter/
Edit:
If you want to directly open another app you can use something like this:
https://pub.dev/packages/external_app_launcher/
flutter pub add external_app_launcher
The Code would look like this then:
await LaunchApp.openApp(
androidPackageName: 'net.pulsesecure.pulsesecure',
iosUrlScheme: 'pulsesecure://',
appStoreLink: 'itms-apps://itunes.apple.com/us/app/pulse secure/id945832041',// openStore: false
);
// Enter the package name of the App you want to open and for iOS add the URLscheme to the Info.plist file.
// The `openStore` argument decides whether the app redirects to PlayStore or AppStore.
// For testing purpose you can enter com.instagram.android
More infos regarding implementation and additional setup infos you can find here: https://pub.dev/packages/external_app_launcher in the Readme

Is there a way to launch Safari or some other external browser on URLs in Flutter apps on iOS?

I have this code:
import 'package:url_launcher/url_launcher.dart';
...
await launch("https://example.org/bigprizes");
It launches a web view within the app on iOS. Instead, I want it to launch in Safari or some other external browser of the user's choice. Is there a way to do that in Flutter?
Look at Step 4 in https://www.digitalocean.com/community/tutorials/flutter-url-launcher
await launch("https://example.org/bigprizes", forceSafariVC: false);
url_launcher plugin (https://pub.dev/packages/url_launcher) has methods launchUrl() and launchUrlString() which both has a property mode where you can specify how the app will open the URL. More details on the Launch mode documentation
Basically you can call it like this:
static Future<void> launchURL(String url) async {
if (await canLaunchUrlString(url)) {
// Passes the URL to the OS to be handled by another application.
await launchUrlString(url, mode: LaunchMode.externalApplication);
} else {
throw 'Could not launch $url';
}
}
check this package https://pub.dev/packages/flutter_linkify it's may be useful for your project

Flutter ,Google apis wants choose gmail adress every time

I'm using google calender API and google sign-in in Flutter but when I try to log in, google wants to choose Gmail address every time.
When I was using google sign in without google calender API, my app was logging in automatically after the first login. Then I added google calender API and Google starts to wants me to choose a Gmail account every time.
How can I choose Google signed-in account for google API?
There is the code.
final GoogleSignIn googleSignIn = GoogleSignIn(
clientId:"THIS IS CLIENT ID"
scopes: [
'https://www.googleapis.com/auth/calendar',
],
);
clientViaUserConsent(ClientId(googleSignIn.clientId, ''),
[CalendarApi.CalendarScope], prompt)
.then((AuthClient client) {
Constants.baseCl = client;
});
void prompt(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}

Is there any twitter authentication for flutter web?

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

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.