AgentforceAuthCredentialProviding

Overview

Protocol that provides authentication credentials for Agentforce service communication. Implement this protocol to supply the SDK with the necessary authentication tokens and credentials required to establish secure connections with Agentforce services.

Declaration

protocol AgentforceAuthCredentialProviding

Methods

Method Signature Description
getAuthCredentials func getAuthCredentials() -> AgentforceAuthCredentials Returns the current authentication credentials for Agentforce service access.
fetchMIAWJWTForPassthrough func fetchMIAWJWTForPassthrough(pathOrUrl:serviceApiURL:esDeveloperName:) async throws -> PassthroughVerification? Fetches MIAW JWT from the passthrough endpoint for user verification. This method allows credential providers that have access to SalesforceSDKCore to use RestRequest instead of URLRequest for better authentication handling.

Implementation Patterns

class OAuthCredentialProvider: AgentforceAuthCredentialProviding {
    func getAuthCredentials() -> AgentforceAuthCredentials {
        // Retrieve OAuth token from your authentication system
        let token = AuthManager.shared.currentAccessToken
        let orgId = AuthManager.shared.currentOrgId
        let userId = AuthManager.shared.currentUserId

        return .OAuth(authToken: token, orgId: orgId, userId: userId)
    }

    func fetchMIAWJWTForPassthrough(
        pathOrUrl: String,
        serviceApiURL: String,
        esDeveloperName: String
    ) async throws -> PassthroughVerification? {
        // Implement passthrough JWT fetching if needed
        // Default implementation throws MIAWJWTFetchNotImplemented
        throw AgentforceError.MIAWJWTFetchNotImplemented
    }
}
class GuestCredentialProvider: AgentforceAuthCredentialProviding {
    func getAuthCredentials() -> AgentforceAuthCredentials {
        return .Guest(url: "https://myorg.salesforce.com")
    }

    func fetchMIAWJWTForPassthrough(
        pathOrUrl: String,
        serviceApiURL: String,
        esDeveloperName: String
    ) async throws -> PassthroughVerification? {
        throw AgentforceError.MIAWJWTFetchNotImplemented
    }
}