-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmanagement_client_example.php
More file actions
125 lines (104 loc) · 4.63 KB
/
management_client_example.php
File metadata and controls
125 lines (104 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Kinde Management Client Example
*
* This example demonstrates how to use the KindeManagementClient
* for server-to-server operations.
*/
require_once __DIR__ . '/../vendor/autoload.php';
use Kinde\KindeSDK\KindeManagementClient;
use Kinde\KindeSDK\ApiException;
// Load environment variables (you can use .env file or set them directly)
// $_ENV['KINDE_DOMAIN'] = 'https://your-domain.kinde.com';
// $_ENV['KINDE_CLIENT_ID'] = 'your_client_id';
// $_ENV['KINDE_CLIENT_SECRET'] = 'your_client_secret';
try {
// Create management client from environment variables (recommended)
$management = KindeManagementClient::createFromEnv();
// Alternative initialization methods:
// $management = new KindeManagementClient(); // Same as createFromEnv()
// $management = new KindeManagementClient('https://custom-domain.kinde.com'); // Override domain
// $management = new KindeManagementClient(null, null, null, 'custom_token'); // Override token
echo "✅ Management client created successfully\n";
echo "Domain: " . $management->getDomain() . "\n";
echo "Client ID: " . $management->getClientId() . "\n";
// Example 1: Get users
echo "\n📋 Getting users...\n";
try {
$users = $management->users->getUsers();
echo "Found " . count($users->getUsers()) . " users\n";
$userList = $users->getUsers() ?? [];
foreach ($userList as $user) {
$givenName = $user->getGivenName() ?? '';
$familyName = $user->getFamilyName() ?? '';
$email = $user->getEmail() ?? '';
echo "- {$givenName} {$familyName} ({$email})\n";
}
} catch (ApiException $e) {
echo "❌ Failed to get users: {$e->getMessage()}\n";
}
// Example 2: Get organizations
echo "\n🏢 Getting organizations...\n";
try {
$organizations = $management->organizations->getOrganizations();
echo "Found " . count($organizations->getOrganizations()) . " organizations\n";
foreach ($organizations->getOrganizations() as $org) {
echo "- {$org->getName()} (ID: {$org->getCode()})\n";
}
} catch (ApiException $e) {
echo "❌ Failed to get organizations: {$e->getMessage()}\n";
}
// Example 3: Get applications
echo "\n📱 Getting applications...\n";
try {
$applications = $management->applications->getApplications();
echo "Found " . count($applications->getApplications()) . " applications\n";
foreach ($applications->getApplications() as $app) {
echo "- {$app->getName()} (Type: {$app->getType()})\n";
}
} catch (ApiException $e) {
echo "❌ Failed to get applications: {$e->getMessage()}\n";
}
// Example 4: Get feature flags
echo "\n🚩 Getting feature flags...\n";
try {
$featureFlags = $management->featureFlags->getEnvironmentFeatureFlags();
echo "Found " . count($featureFlags->getFeatureFlags()) . " feature flags\n";
foreach ($featureFlags->getFeatureFlags() as $flag) {
$value = $flag->getValue();
$displayValue = $value === null ? 'null' : ($value ? 'true' : 'false');
echo "- {$flag->getName()} (Type: {$flag->getType()}, Value: {$displayValue})\n";
}
} catch (ApiException $e) {
echo "❌ Failed to get feature flags: {$e->getMessage()}\n";
}
// Example 5: Get roles
echo "\n👥 Getting roles...\n";
try {
$roles = $management->roles->getRoles();
echo "Found " . count($roles->getRoles()) . " roles\n";
foreach ($roles->getRoles() as $role) {
echo "- {$role->getName()} ({$role->getDescription()})\n";
}
} catch (ApiException $e) {
echo "❌ Failed to get roles: {$e->getMessage()}\n";
}
// Example 6: Get permissions
echo "\n🔐 Getting permissions...\n";
try {
$permissions = $management->permissions->getPermissions();
echo "Found " . count($permissions->getPermissions()) . " permissions\n";
foreach ($permissions->getPermissions() as $permission) {
echo "- {$permission->getName()} ({$permission->getDescription()})\n";
}
} catch (ApiException $e) {
echo "❌ Failed to get permissions: {$e->getMessage()}\n";
}
echo "\n✅ Management client example completed successfully!\n";
} catch (Exception $e) {
echo "❌ Error: {$e->getMessage()}\n";
echo "Make sure you have set the required environment variables:\n";
echo "- KINDE_DOMAIN\n";
echo "- KINDE_CLIENT_ID\n";
echo "- KINDE_CLIENT_SECRET\n";
}