In Okta SDK version 7, the approach to retrieve policy rules along with their details like userIdentifier and patterns has changed. The OktaClient class and its methods you were using are no longer available. Instead, you can use the Policy API directly to get the policy and its rules. Here’s an updated way to retrieve the same data:
// Assuming you have set up your Okta client configuration
var oktaClient = new OktaClient(new OktaClientConfiguration
{
OktaDomain = “https://{yourOktaDomain}”,
Token = “{apiToken}”
});
// Get a policy along with its rules
var policy = await oktaClient.Policies.GetPolicyAsync(policyId, “expand=rules”);
// List all policy rules
var rules = await policy.ListPolicyRules(oktaClient).ToListAsync();
// Iterate over the rules to get userIdentifier and patterns
foreach (var rule in rules)
{
var userIdentifier = rule.Conditions.People.Users;
var patterns = rule.Conditions.People.Groups;
// Process the userIdentifier and patterns as needed
}
This code uses the GetPolicyAsync method with the expand=rules parameter to retrieve the policy and its associated rules. The ListPolicyRules method is then used to list all the rules for that policy. You can access the userIdentifier and patterns through the Conditions property of each rule.
Please replace {yourOktaDomain} and {apiToken} with your actual Okta domain and API token. Also, ensure that you have the necessary permissions to access the policy information.
Hello @ryan1969, thank you for your response, but the OktaClient class is removed in the latest version so I can’t use this one right? I don’t get the rule’s patterns in the PolicyApi response.