mobileApplicationsKonectarApp/lib/openid/openid_io.dart

36 lines
993 B
Dart
Raw Permalink Normal View History

2024-01-04 07:06:37 +00:00
import 'dart:io';
import 'package:openid_client/openid_client.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:openid_client/openid_client_io.dart' as io;
Future<Credential> authenticate(Client client,
{List<String> scopes = const []}) async {
// create a function to open a browser with an url
urlLauncher(String url) async {
var uri = Uri.parse(url);
if (await canLaunchUrl(uri) || Platform.isAndroid) {
await launchUrl(uri);
} else {
throw 'Could not launch $url';
}
}
// create an authenticator
var authenticator = io.Authenticator(client,
scopes: scopes, port: 3000, urlLancher: urlLauncher, redirectMessage: 'Logged In..' );
var c = await authenticator.authorize();
// close the webview when finished
if (Platform.isAndroid || Platform.isIOS) {
closeInAppWebView();
}
return c;
}
Future<Credential?> getRedirectResult(Client client,
{List<String> scopes = const []}) async {
return null;
}