Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for authority TFP format to work with iOS #24

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions ios/Classes/B2CProvider.swift
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi alex-dokienko,
this breaks support to authorities that do not have tfp in the url... it should be placed a check like you placed in other parts.
Moreover, one way to declare to MSAL that an authority is a B2C is to specify it in the configuration json like this:
{
"type": "B2C",
"authority_url": "https://contoso.b2clogin.com/contoso.onmicrosoft.com/PolicyName/",
"default": true
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi alex-dokienko,

Let's say you almost solved the problem but there is still a problem in the "getAuthorityFromPolicyName" function.

I say to solve the problem you could add a private variable "bool isTFPFormat" to the B2CProvider that could be initialized during the "initMSAL" function... It should be sufficient to check if the authorityURL contains "/tfp/" like you done in other parts. Then modify the aforementioned function to return proper URL with or without "/tfp/" according to that variable.

Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ class B2CProvider {
private func setHostAndTenantFromAuthority(tag: String, authority: MSALAuthority) {
let parts = authority.url.absoluteString.split(usingRegex: "https://|/")
hostName = parts[1]
tenantName = parts[2]
tenantName = parts[3]
print("B2CProvider [\(tag)] host: \(hostName ?? "nil"), tenant: \(tenantName ?? "nil")")
}

private func getAuthorityFromPolicyName(tag: String, policyName: String, source: String) -> MSALB2CAuthority? {
do {
let urlString = "https://\(hostName!)/\(tenantName!)/\(policyName)/"
let urlString = "https://\(hostName!)/tfp/\(tenantName!)/\(policyName)/"
let authorityURL = URL(string: urlString)!
return try MSALB2CAuthority(url: authorityURL)
}
Expand Down
5 changes: 4 additions & 1 deletion lib/B2CConfiguration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class B2CAuthority {
late final bool isDefault;

/// Return the policy name associathed to the authority.
String get policyName => authorityURL.split(RegExp("https://|/"))[3];
String get policyName =>
(authorityURL.contains('tfp'))
? authorityURL.split(RegExp("https://|/"))[4]
: authorityURL.split(RegExp("https://|/"))[3];

/// Default constructor.
///
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_azure_b2c
description: A flutter library to handle the Azure B2C authentication protocol
version: 0.0.9
version: 0.0.11
homepage: "https://github.com/nodriver-ai/flutter_azure_b2c"

environment:
Expand Down