---
schema_version: "1"
id: a19e1bb773f62a57fbc787eca91a62c2711f8c72921a37019a546de3dd590927
title: AgentforceAuthCredentialProviding
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/genai/agentforce-mobile-sdk/references/ios/agentforce-auth-credential-providing-ios.md
canonical_url: https://developer.salesforce.com/docs/ai/agentforce-mobile-sdk/references/agentforce-mobile-sdk/agentforce-auth-credential-providing-ios.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 141c6eafca5d1ee0ecd6fd116b575940a9a971ec2ebf3b849f4a890f9a283487
products:
  - Agentforce Mobile SDK
  - Agentforce and Einstein Generative AI
---
# 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

```swift
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

```swift
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
    }
}
```

```swift
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
    }
}
```
