Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Migrate to MSAL 1.2.0 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 1.2.0
* Updated to MSAL 1.2.0+
## 1.0.0+2
* Updates to readme in regards to kotlin static field issues.
## 1.0.0+1
Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group 'uk.co.moodio.msal_flutter'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.30'
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
Expand Down Expand Up @@ -42,6 +42,6 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.microsoft.identity.client:msal:1.0.+'
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${kotlin_version}"
implementation 'com.microsoft.identity.client:msal:1.2.+'
}
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'msal_flutter'
rootProject.name = 'msal_flutter'
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ class MsalFlutterPlugin: MethodCallHandler {
val scopes: Array<String>? = scopesArg?.toTypedArray()
val clientId : String? = call.argument("clientId")
val authority : String? = call.argument("authority")
val redirectUri : String? = call.argument("redirectUri");

Log.d("MsalFlutter","Got scopes: $scopes")
Log.d("MsalFlutter","Got cleintId: $clientId")
Log.d("MsalFlutter","Got clientId: $clientId")
Log.d("MsalFlutter","Got authority: $authority")

when(call.method){
"logout" -> Thread(Runnable{logout(result)}).start()
"initialize" -> initialize(clientId, authority, result)
"initialize" -> initialize(clientId, authority, redirectUri.orEmpty(), result)
"acquireToken" -> Thread(Runnable {acquireToken(scopes, result)}).start()
"acquireTokenSilent" -> Thread(Runnable {acquireTokenSilent(scopes, result)}).start()
else -> result.notImplemented()
Expand Down Expand Up @@ -168,7 +169,7 @@ class MsalFlutterPlugin: MethodCallHandler {
}
}

private fun initialize(clientId: String?, authority: String?, result: Result)
private fun initialize(clientId: String?, authority: String?, redirectUri: String, result: Result)
{
//ensure clientid provided
if(clientId == null){
Expand All @@ -177,6 +178,13 @@ class MsalFlutterPlugin: MethodCallHandler {
return
}

//ensure redirectUri provided
if (redirectUri.isEmpty()){
Log.d("MsalFlutter","error no redirectUri")
result.error("NO_REDIRECTURI", "Call must include a redirectUri", null)
return
}

//if already initialized, ensure clientid hasn't changed
if(isClientInitialized()){
Log.d("MsalFlutter","Client already initialized.")
Expand All @@ -192,11 +200,10 @@ class MsalFlutterPlugin: MethodCallHandler {
if(authority != null){
Log.d("MsalFlutter", "Authority not null")
Log.d("MsalFlutter", "Creating with: $clientId - $authority")
PublicClientApplication.create(mainActivity.applicationContext, clientId, authority, getApplicationCreatedListener(result))
}else{
Log.d("MsalFlutter", "Authority null")
PublicClientApplication.create(mainActivity.applicationContext, clientId, getApplicationCreatedListener(result))
}
PublicClientApplication.create(mainActivity.applicationContext, clientId, null, redirectUri, getApplicationCreatedListener(result));
}


Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
10 changes: 0 additions & 10 deletions example/ios/Flutter/flutter_export_environment.sh

This file was deleted.

89 changes: 54 additions & 35 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '11.0'
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand All @@ -15,53 +15,72 @@ def parse_KV_file(file, separator='=')
if !File.exists? file_abs_path
return [];
end
pods_ary = []
generated_key_values = {}
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) { |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts "Invalid plugin specification: #{line}"
end
}
return pods_ary
File.foreach(file_abs_path) do |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
generated_key_values[podname] = podpath
else
puts "Invalid plugin specification: #{line}"
end
end
generated_key_values
end

target 'Runner' do
use_frameworks!
use_modular_headers!

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
# Flutter Pod

# Flutter Pods
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
if generated_xcode_build_settings.empty?
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
end
generated_xcode_build_settings.map { |p|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
symlink = File.join('.symlinks', 'flutter')
File.symlink(File.dirname(p[:path]), symlink)
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
copied_flutter_dir = File.join(__dir__, 'Flutter')
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.

generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
unless File.exist?(generated_xcode_build_settings_path)
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

unless File.exist?(copied_framework_path)
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
end
}
unless File.exist?(copied_podspec_path)
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
end
end

# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter', :path => 'Flutter'

# Plugin Pods

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.map { |p|
symlink = File.join('.symlinks', 'plugins', p[:name])
File.symlink(p[:path], symlink)
pod p[:name], :path => File.join(symlink, 'ios')
}
plugin_pods.each do |name, path|
symlink = File.join('.symlinks', 'plugins', name)
File.symlink(path, symlink)
pod name, :path => File.join(symlink, 'ios')
end
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ PODS:
- MSAL (1.0.3):
- MSAL/app-lib (= 1.0.3)
- MSAL/app-lib (1.0.3)
- msal_flutter (1.0.0):
- msal_flutter (1.2.0):
- Flutter
- MSAL (~> 1.0.3)

DEPENDENCIES:
- Flutter (from `.symlinks/flutter/ios`)
- Flutter (from `Flutter`)
- msal_flutter (from `.symlinks/plugins/msal_flutter/ios`)

SPEC REPOS:
Expand All @@ -17,15 +17,15 @@ SPEC REPOS:

EXTERNAL SOURCES:
Flutter:
:path: ".symlinks/flutter/ios"
:path: Flutter
msal_flutter:
:path: ".symlinks/plugins/msal_flutter/ios"

SPEC CHECKSUMS:
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
MSAL: 351711995bd31170a2e887941115a3ed17b178e8
msal_flutter: 72ba12187cce21c6a39282189431964c71033c80
msal_flutter: 8662227d408b2d685147aaf7d37e5fc8131b067b

PODFILE CHECKSUM: 58760ca3c5878cb71ae11bd6eeff33fd4ce06e4f
PODFILE CHECKSUM: 083258d7f5e80b42ea9bfee905fe93049bc04c64

COCOAPODS: 1.8.4
7 changes: 0 additions & 7 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,9 @@
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/MSAL/MSAL.framework",
"${BUILT_PRODUCTS_DIR}/msal_flutter/msal_flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MSAL.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/msal_flutter.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
15 changes: 8 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {

static const String _authority = "https://msalfluttertest.b2clogin.com/tfp/msalfluttertest.onmicrosoft.com/B2C_1_sisu";
static const String _clientId = "5913dfb1-7576-451c-a7ea-a7c5a3f8682a";

static const String _redirectUrl = "msauth://com.example.msal/PbN3nCasHqLUVarghPLaQWerTYU%3D";

String _output = 'NONE';

PublicClientApplication pca;

Future<void> _acquireToken() async{
if(pca == null){
pca = await PublicClientApplication.createPublicClientApplication(_clientId, authority: _authority);
pca = await PublicClientApplication.createPublicClientApplication(_clientId, _redirectUrl, authority: _authority);
}

String res;
Expand All @@ -47,9 +48,9 @@ class _MyAppState extends State<MyApp> {

Future<void> _acquireTokenSilently() async {
if(pca == null){
pca = await PublicClientApplication.createPublicClientApplication(_clientId, authority: _authority);
pca = await PublicClientApplication.createPublicClientApplication(_clientId, _redirectUrl, authority: _authority);
}

String res;
try
{
Expand All @@ -74,7 +75,7 @@ class _MyAppState extends State<MyApp> {
Future _logout() async {
print("called logout");
if(pca == null){
pca = await PublicClientApplication.createPublicClientApplication(_clientId, authority: _authority);
pca = await PublicClientApplication.createPublicClientApplication(_clientId, _redirectUrl, authority: _authority);
}

print("pca is not null");
Expand Down Expand Up @@ -104,7 +105,7 @@ class _MyAppState extends State<MyApp> {
body: Center(
child: Column(
children: <Widget>[
RaisedButton( onPressed: _acquireToken,
RaisedButton( onPressed: _acquireToken,
child: Text('AcquireToken()'),),
RaisedButton( onPressed: _acquireTokenSilently,
child: Text('AcquireTokenSilently()')),
Expand Down
Loading