Step 3. Authenticating with external IdPs
PingOne Advanced Identity Cloud PingAM iOS
Your app must handle the relevant node types your server returns when a user attempts to authenticate using an external IdP.
When encountering the IdpCallback, call authorize() to begin authentication with the external IdP:
public class SocialButtonViewModel: ObservableObject {
@Published public var isComplete: Bool = false
public let idpCallback: IdpCallback
public init(idpCallback: IdpCallback) {
self.idpCallback = idpCallback
}
public func startSocialAuthentication() async -> Result<Bool, IdpExceptions> {
return await idpCallback.authorize()
}
public func socialButtonText() -> some View {
let bgColor: Color
switch idpCallback.idpType {
case "APPLE":
bgColor = Color.appleButtonBackground
case "GOOGLE":
bgColor = Color.googleButtonBackground
case "FACEBOOK":
bgColor = Color.facebookButtonBackground
default:
bgColor = Color.themeButtonBackground
}
let text = Text(idpCallback.label)
.font(.headline)
.foregroundColor(.white)
.padding()
.frame(width: 300, height: 50)
.background(bgColor)
.cornerRadius(15.0)
return text
}
}
The authorize() method returns a Success result when authentication with the external IdP completes successfully. If not, it returns Failure and IdpExceptions, which shows the root cause of the issue.
Task {
let result = await socialButtonViewModel.startSocialAuthentication()
switch result {
case .success(_):
onNext(true)
case .failure(let error): //<- Exception
onStart()
}
}