Home > database >  MSAL and IOS - Can't figure out the authority for my B2C instance
MSAL and IOS - Can't figure out the authority for my B2C instance

Time:01-07

I have created a B2C instance called myB2CDemonstration and there I created a Experience Framework flow called B2C_1A-SIGNUP_SIGNIN.

My code looks like this:

let kClientID = "d7628 ... 4a34d"
let kGraphEndpoint = "https://graph.microsoft.com/"
let kAuthority1 = "https://login.microsoftonline.com/7fb6a ... 427"
let kAuthority2 = "https://myB2CDemonstration.b2clogin.com/myB2CDemonstration.onmicrosoft.com/B2C_1A_SIGNUP_SIGNIN"
let kAuthority3 = "https://myB2CDemonstration.onmicrosoft.com/7fb6a ... 427"
let kRedirectUri = "msauth.br.com.edenred.ticket://auth"

let kAuthority = kAuthority1 // or 2 or 3

guard let authorityURL = URL(string: kAuthority) else {
      self.updateLogging(text: "Unable to create authority URL")
      return
  }
  
  let authority = try MSALAADAuthority(url: authorityURL)
  
  let msalConfiguration = MSALPublicClientApplicationConfig(clientId: kClientID,
                                                            redirectUri: kRedirectUri,
                                                            authority: authority)
  msalConfiguration.knownAuthorities = [authority]
  self.applicationContext = try MSALPublicClientApplication(configuration: msalConfiguration)
  self.initWebViewParams()

if I use kAuthority1 or kAuthority2 I get the error

Could not acquire token: Error Domain=MSALErrorDomain Code=-50000 UserInfo={MSALErrorDescriotionKey=AADSTS50049: Unknown or invalid instance. MSALOAutherrorKey=invalid_instance, MSALInternalErrorCOdeKey=-42010} (and a bunch of trace ids e correlation ids and etc)

if I use kAuthority3 I get the error

The operation couldn’t be completed. (MSIDErrorDomain error -51112.) TID=3929455 MSAL 1.2.5 iOS Sim 16.2 [2023-01-05 20:48:01] Creating Error with description: Trying to initialize AAD authority with B2C authority url.

can anyone tell me what im doing wrong?

CodePudding user response:

Try the sample here, you seem to be using an AAD sample. https://learn.microsoft.com/en-us/azure/active-directory-b2c/configure-authentication-sample-ios-app

CodePudding user response:

I actually got it myself: I changed the MSALAADAuthority to MSALB2CAuthority and removed the scopes and used the variant 2 (with name of tenant and no GUIDs)

  • Related