Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit f35c9fd

Browse files
authored
Merge pull request #26 from Azure-Samples/jennyf/fixb2clogin
Replace login.microsoftonline.com w/b2clogin.com
2 parents 473303d + 218c738 commit f35c9fd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

MSALiOSB2C/ViewController.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import MSAL
3434
class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate {
3535

3636
let kTenantName = "fabrikamb2c.onmicrosoft.com" // Your tenant name
37+
let kAuthorityHostName = "fabrikamb2c.b2clogin.com" // Your authority host name
3738
let kClientID = "90c0fe63-bcf2-44d5-8fb7-b8bbc0b29dc6" // Your client ID from the portal when you created your application
3839
let kSignupOrSigninPolicy = "b2c_1_susi" // Your signup and sign-in policy you created in the portal
3940
let kEditProfilePolicy = "b2c_1_edit_profile" // Your edit policy you created in the portal
@@ -42,7 +43,7 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
4243
let kScopes: [String] = ["https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read"] // This is a scope that you've configured your backend API to look for.
4344

4445
// DO NOT CHANGE - This is the format of OIDC Token and Authorization endpoints for Azure AD B2C.
45-
let kEndpoint = "https://login.microsoftonline.com/tfp/%@/%@"
46+
let kEndpoint = "https://%@/tfp/%@/%@"
4647

4748
var application: MSALPublicClientApplication!
4849

@@ -66,11 +67,13 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
6667
The scheme part, i.e. "msal<your-client-id-here>", needs to be registered in the info.plist of the project
6768
*/
6869

69-
let authority = try self.getAuthority(forPolicy: self.kSignupOrSigninPolicy)
70-
70+
let siginPolicyAuthority = try self.getAuthority(forPolicy: self.kSignupOrSigninPolicy)
71+
let editProfileAuthority = try self.getAuthority(forPolicy: self.kEditProfilePolicy)
72+
7173
// Provide configuration for MSALPublicClientApplication
7274
// MSAL will use default redirect uri when you provide nil
73-
let pcaConfig = MSALPublicClientApplicationConfig(clientId: kClientID, redirectUri: nil, authority: authority)
75+
let pcaConfig = MSALPublicClientApplicationConfig(clientId: kClientID, redirectUri: nil, authority: siginPolicyAuthority)
76+
pcaConfig.knownAuthorities = [siginPolicyAuthority, editProfileAuthority]
7477
self.application = try MSALPublicClientApplication(configuration: pcaConfig)
7578
} catch {
7679
self.updateLoggingText(text: "Unable to create application \(error)")
@@ -364,7 +367,7 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
364367
use for the current user flow.
365368
*/
366369
func getAuthority(forPolicy policy: String) throws -> MSALB2CAuthority {
367-
guard let authorityURL = URL(string: String(format: self.kEndpoint, self.kTenantName, policy)) else {
370+
guard let authorityURL = URL(string: String(format: self.kEndpoint, self.kAuthorityHostName, self.kTenantName, policy)) else {
368371
throw NSError(domain: "SomeDomain",
369372
code: 1,
370373
userInfo: ["errorDescription": "Unable to create authority URL!"])

0 commit comments

Comments
 (0)