init method
Future<void>
init({
- required String clientId,
- String? loginHint,
- AndroidConfig? androidConfig,
- IosConfig? iosConfig,
override
Initializes MSAL with required data.
Implementation
@override
Future<void> init({
required String clientId,
String? loginHint,
AndroidConfig? androidConfig,
IosConfig? iosConfig,
}) async {
await _ErrorHandler.guard(() async {
late final Map<String, dynamic> arguments;
if (Platform.isAndroid) {
assert(androidConfig != null, 'Android config can not be null');
final config =
await rootBundle.loadString(androidConfig!.configFilePath);
final map = json.decode(config) as Map<String, dynamic>;
map['client_id'] = clientId;
if (androidConfig.tenantId != null) {
map['authorities'][0]['audience']['tenant_id'] =
androidConfig.tenantId;
}
final directory = await getApplicationDocumentsDirectory();
final file = File('${directory.path}/msal_auth_config.json');
await file.writeAsBytes(utf8.encode(json.encode(map)));
arguments = {'configFilePath': file.path};
} else if (Platform.isIOS) {
assert(iosConfig != null, 'iOS config can not be null');
arguments = <String, dynamic>{
'clientId': clientId,
'authority': iosConfig!.authority,
'authMiddleware': iosConfig.authMiddleware.name,
'tenantType': iosConfig.tenantType.name,
'loginHint': loginHint,
};
}
await methodChannel.invokeMethod('initialize', arguments);
});
}