Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.
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
13 changes: 8 additions & 5 deletions ios/Classes/SwiftMsalFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import MSAL
public class SwiftMsalFlutterPlugin: NSObject, FlutterPlugin {

//static fields as initialization isn't really required
static var clientId : String = ""
static var authority : String = ""
static var clientId : String = ""
static var authority : String = ""
static var redirectURI : String?

public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "msal_flutter", binaryMessenger: registrar.messenger())
Expand All @@ -21,9 +22,10 @@ public class SwiftMsalFlutterPlugin: NSObject, FlutterPlugin {
let scopes = dict["scopes"] as? [String] ?? [String]()
let clientId = dict["clientId"] as? String ?? ""
let authority = dict["authority"] as? String ?? ""
let redirectURI = dict["redirectURI"] as? String ?? ""

switch( call.method ){
case "initialize": initialize(clientId: clientId, authority: authority, result: result)
case "initialize": initialize(clientId: clientId, authority: authority, redirectURI: redirectURI, result: result)
case "acquireToken": acquireToken(scopes: scopes, result: result)
case "acquireTokenSilent": acquireTokenSilent(scopes: scopes, result: result)
case "logout": logout(result: result)
Expand Down Expand Up @@ -125,7 +127,7 @@ public class SwiftMsalFlutterPlugin: NSObject, FlutterPlugin {

//create the msal authority and configuration
let msalAuthority = try MSALAuthority(url: authorityUrl)
config = MSALPublicClientApplicationConfig(clientId: SwiftMsalFlutterPlugin.clientId, redirectUri: nil, authority: msalAuthority)
config = MSALPublicClientApplicationConfig(clientId: SwiftMsalFlutterPlugin.clientId, redirectUri: SwiftMsalFlutterPlugin.redirectURI, authority: msalAuthority)
} catch {
//return error if exception occurs
result(FlutterError(code: "INVALID_AUTHORITY", message: "invalid authority", details: nil))
Expand All @@ -148,7 +150,7 @@ public class SwiftMsalFlutterPlugin: NSObject, FlutterPlugin {
}
}

private func initialize(clientId: String, authority: String, result: @escaping FlutterResult)
private func initialize(clientId: String, authority: String, redirectURI: String?, result: @escaping FlutterResult)
{
//validate clientid exists
if(clientId.isEmpty){
Expand All @@ -158,6 +160,7 @@ public class SwiftMsalFlutterPlugin: NSObject, FlutterPlugin {

SwiftMsalFlutterPlugin.clientId = clientId;
SwiftMsalFlutterPlugin.authority = authority;
SwiftMsalFlutterPlugin.redirectURI = redirectURI
result(true)
}

Expand Down
12 changes: 8 additions & 4 deletions lib/src/public_client_application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'msal_exception.dart';
class PublicClientApplication {
static const MethodChannel _channel = const MethodChannel('msal_flutter');

String _clientId, _authority;
String _clientId, _authority, _redirectURI;

/// Create a new PublicClientApplication authenticating as the given [clientId],
/// optionally against the selected [authority], defaulting to the common
Expand All @@ -15,15 +15,16 @@ class PublicClientApplication {
"Direct call is no longer supported in v1.0, please use static method createPublicClientApplication");
}

PublicClientApplication._create(String clientId, {String authority}) {
PublicClientApplication._create(String clientId, {String authority, String redirectURI}) {
_clientId = clientId;
_authority = authority;
_redirectURI = redirectURI;
}

static Future<PublicClientApplication> createPublicClientApplication(
String clientId,
{String authority}) async {
var res = PublicClientApplication._create(clientId, authority: authority);
{String authority, String redirectURI}) async {
var res = PublicClientApplication._create(clientId, authority: authority, redirectURI: redirectURI);
await res._initialize();
return res;
}
Expand Down Expand Up @@ -99,6 +100,9 @@ class PublicClientApplication {
if (this._authority != null) {
res["authority"] = this._authority;
}
if (this._redirectURI != null) {
res["redirectURI"] = this._redirectURI;
}

try {
await _channel.invokeMethod('initialize', res);
Expand Down