Logo

Authentication

The host application must implement EcoAuthenticationProtocol to provide the current access token and handle token refresh after an unauthorized response.

Implementing EcoAuthenticationProtocol

final class MyAuthManager: EcoAuthenticationProtocol {
    func didReceiveUnauthorizedResponse(
        completion: @escaping (_ tokenRefreshed: Bool) -> Void
    ) {
        // Refresh the access token.
        // Call completion(true) when the refresh succeeds.
        // Call completion(false) when the refresh fails.
        refreshToken { success in
            completion(success)
        }
    }

    func currentAccessToken() -> String? {
        // Return the current access token.
        UserDefaults.standard.string(forKey: "accessToken")
    }
}