PushCredential
public struct PushCredential : Codable, Identifiable, @unchecked Sendable, CustomStringConvertible
Represents a Push credential for push authentication.
A Push credential contains all the information needed to register a device for push notifications and to authenticate using push challenges. This model follows the PingAM (ForgeRock) push authentication protocol.
Credential Sources
Push credentials are typically created by:
- Scanning a QR code containing a
pushauth://ormfauth://URI - Receiving credential information from a server API
- Importing from backup or migration
Security Considerations
- The
sharedSecretis used for cryptographic operations and must be protected - Credentials can be locked based on policy violations
- All credential data should be stored securely in the Keychain
Usage Example
// From QR code
let credential = try await PushCredential.fromUri(qrCodeUri)
// Manual creation
let credential = PushCredential(
issuer: "MyCompany",
accountName: "user@example.com",
serverEndpoint: "https://am.example.com/push",
sharedSecret: "base64EncodedSecret"
)
-
Unique identifier for the credential (local ID).
Declaration
Swift
public let id: String -
User identifier on the server.
Declaration
Swift
public let userId: String? -
Server-side device identifier. If not provided during initialization, defaults to the credential ID.
Declaration
Swift
public let resourceId: String -
The name of the issuer for this credential.
Declaration
Swift
public let issuer: String -
The name of the issuer for this credential, editable by the user.
Declaration
Swift
public var displayIssuer: String -
The account name associated with this credential.
Declaration
Swift
public let accountName: String -
The account name associated with this credential, editable by the user.
Declaration
Swift
public var displayAccountName: String -
The endpoint where authentication responses should be sent. This is the base URL for push operations (registration, authentication, update).
Declaration
Swift
public let serverEndpoint: String -
The timestamp when this credential was created.
Declaration
Swift
public let createdAt: Date -
Optional URL for the issuer’s logo or image.
Declaration
Swift
public let imageURL: String? -
Optional background color for the credential (hex format).
Declaration
Swift
public let backgroundColor: String? -
Optional Authenticator Policies in a JSON String format for the credential.
Declaration
Swift
public let policies: String? -
Optional name of the Policy locking the credential.
Declaration
Swift
public var lockingPolicy: String? -
Indicates whether the credential is locked.
Declaration
Swift
public var isLocked: Bool -
The platform for which this credential is intended (e.g., PING_AM).
Declaration
Swift
public let platform: PushPlatform -
Optional additional data associated with this credential. Note: This is not directly encoded/decoded due to type erasure limitations.
Declaration
Swift
public var additionalData: [String : Any]?
-
Returns the registration endpoint for this credential. This is used to register the device with the PingAM servers.
Declaration
Swift
public var registrationEndpoint: String { get } -
Returns the authentication endpoint for this credential. This is used to authenticate the user via push notification with the PingAM servers.
Declaration
Swift
public var authenticationEndpoint: String { get } -
Returns the update endpoint for this credential. This is used to refresh or update the device token with the PingAM servers.
Declaration
Swift
public var updateEndpoint: String { get }
-
Declaration
Swift
public var description: String { get }
-
init(id:userId: resourceId: issuer: displayIssuer: accountName: displayAccountName: serverEndpoint: sharedSecret: createdAt: imageURL: backgroundColor: policies: lockingPolicy: isLocked: platform: additionalData: ) Creates a new Push credential.
Declaration
Swift
public init( id: String = UUID().uuidString, userId: String? = nil, resourceId: String? = nil, issuer: String, displayIssuer: String? = nil, accountName: String, displayAccountName: String? = nil, serverEndpoint: String, sharedSecret: String, createdAt: Date = Date(), imageURL: String? = nil, backgroundColor: String? = nil, policies: String? = nil, lockingPolicy: String? = nil, isLocked: Bool = false, platform: PushPlatform = .pingAM, additionalData: [String: Any]? = nil )Parameters
idUnique identifier for the credential. Defaults to a new UUID.
userIdUser identifier on the server.
resourceIdServer-side device identifier. Defaults to id if not provided.
issuerThe name of the issuer for this credential.
displayIssuerThe display name of the issuer, editable by the user.
accountNameThe account name associated with this credential.
displayAccountNameThe display account name, editable by the user.
serverEndpointThe endpoint where authentication responses should be sent.
sharedSecretThe secret key used for cryptographic operations.
createdAtThe creation timestamp. Defaults to current date.
imageURLOptional URL for the issuer’s image.
backgroundColorOptional background color.
policiesOptional policies in JSON format.
lockingPolicyOptional locking policy name.
isLockedWhether the credential is locked. Defaults to false.
platformThe platform for this credential. Defaults to PING_AM.
additionalDataOptional additional data.
-
fromUri(_:Asynchronous) Creates a Push credential from a URI string.
This method parses a
pushauth://ormfauth://URI (typically from a QR code) and creates a credential with the extracted information.Throws
PushError.invalidUriif the URI is malformed.Example
let uri = "pushauth://push/MyCompany:user@example.com?r=https://...&s=secret..." let credential = try await PushCredential.fromUri(uri)Declaration
Swift
public static func fromUri(_ uri: String) async throws -> PushCredentialParameters
uriThe pushauth:// or mfauth:// URI string to parse.
Return Value
A new PushCredential instance.
-
toUri()AsynchronousConverts this credential to a URI string.
This method creates a
pushauth://ormfauth://URI that can be used to transfer or backup the credential (e.g., as a QR code).Throws
PushError.uriFormattingif formatting fails.Example
let uri = try await credential.toUri() // Use uri to generate QR code for backupDeclaration
Swift
public func toUri() async throws -> StringReturn Value
A URI string representation of this credential.
-
Lock this credential due to policy violations.
Locked credentials cannot be used for authentication until they are unlocked. This is typically enforced by policy evaluators checking for jailbreak, device compromise, or other security violations.
Declaration
Swift
public mutating func lockCredential(policyName: String)Parameters
policyNameThe name of the policy that caused the lock.
-
Unlock this credential.
This removes any locking policy information and allows the credential to be used for authentication again.
Declaration
Swift
public mutating func unlockCredential()
-
Declaration
Swift
public init(from decoder: Decoder) throws -
Declaration
Swift
public func encode(to encoder: Encoder) throws
View on GitHub