The hardcheck functionality has been successfully implemented in the Kinde PHP SDK. When the force_api flag is set to true, the methods getClaim, getClaims, getPermissions, getFlag, and getFeatureFlags will use RESTful APIs wrapped by the OpenAPI generated code stored in Api/Frontend and Model/Frontend instead of parsing JWT tokens.
public bool $forceApi- Controls whether to use API calls or token parsingprivate ?UserProfileV2 $cachedUserProfile- Caches user profile from APIprivate ?GetUserPermissionsResponse $cachedPermissions- Caches permissions from APIprivate ?GetFeatureFlagsResponse $cachedFeatureFlags- Caches feature flags from API
The constructor now accepts an additional parameter:
function __construct(
?string $domain = null,
?string $redirectUri = null,
?string $clientId = null,
?string $clientSecret = null,
?string $grantType = null,
?string $logoutRedirectUri = null,
string $scopes = 'openid profile email offline',
array $additionalParameters = [],
string $protocol = "",
bool $forceApi = false // New parameter
)The force_api flag can be enabled via environment variable:
KINDE_FORCE_API=true- When
force_apiis enabled, retrieves claims from API calls instead of token parsing - Handles different claim types:
feature_flags- UsesgetFeatureFlagsFromApi()org_code- UsesgetPermissionsFromApi()permissions- UsesgetPermissionsFromApi()org_codes- UsesgetUserProfileFromApi()- Other claims - Uses
getUserProfileFromApi()and maps to standard JWT claims
- When
force_apiis enabled, usesgetPermissionsFromApi()instead of token parsing - Returns the same structure:
['orgCode' => string, 'permissions' => array]
- When
force_apiis enabled, usesgetFeatureFlagsFromApi()instead of token parsing - Maintains the same interface and return format
- Creates and configures the API client with the current access token
- Sets the host and access token for API calls
- Retrieves user profile from
/oauth2/v2/user_profileendpoint - Uses
OAuthApi::getUserProfileV2() - Implements caching to avoid repeated API calls
- Retrieves permissions from
/account_api/v1/permissionsendpoint - Uses
PermissionsApi::getUserPermissions() - Returns data in the same format as the original method
- Implements caching to avoid repeated API calls
- Retrieves feature flags from
/account_api/v1/feature_flagsendpoint - Uses
FeatureFlagsApi::getFeatureFlags() - Converts API response to the internal format expected by existing code
- Implements caching to avoid repeated API calls
- Converts API flag type strings to internal type codes
- Maps:
boolean→'b',string→'s',integer→'i'
- Public method to clear all cached API responses
- Useful when fresh data is needed
When force_api is enabled, the following endpoints are used:
- User Profile:
/oauth2/v2/user_profile(OAuthApi::getUserProfileV2) - Permissions:
/account_api/v1/permissions(PermissionsApi::getUserPermissions) - Feature Flags:
/account_api/v1/feature_flags(FeatureFlagsApi::getFeatureFlags)
- All API responses are cached in memory for the lifetime of the client instance
- Cache is cleared when
clearApiCache()is called - Cache is automatically invalidated when a new client instance is created
- This minimizes API calls while ensuring data consistency
$client = new KindeClientSDK(
'https://your-domain.kinde.com',
'http://localhost:8000/auth/callback',
'your_client_id',
'your_client_secret',
GrantType::authorizationCode,
'http://localhost:8000',
'openid profile email offline',
[],
'',
true // Enable force_api
);export KINDE_FORCE_API=true$client->clearApiCache(); // Get fresh data from API- Real-time Data: Always gets the latest data from the server
- No Token Dependency: Doesn't rely on JWT token claims
- Fresh Permissions: Ensures permissions are up-to-date
- Dynamic Feature Flags: Gets the latest feature flag values
- Better Security: Reduces reliance on client-side token data
- Efficient: Only makes API calls for the specific data you need
- Caching: Minimizes API calls through intelligent caching
- The
force_apiflag defaults tofalse, maintaining backward compatibility - All existing code will continue to work without changes
- The same method signatures are preserved
- Return formats remain consistent
The implementation includes comprehensive tests in tests/Unit/HardcheckTest.php that verify:
- Constructor parameter handling
- Environment variable support
- Method existence and visibility
- Property existence and visibility
- Default behavior (force_api disabled)
All tests pass successfully, ensuring the implementation is robust and reliable.