Click or drag to resize
Quick Start

This quick start is designed to outline the basics of the Okta SDK.

Prerequisites

Add the library as a dependency by following the installation instructions

Create a Client

Create an Okta client with an API token and production subdomain (your_subdomain.okta.com). All clients have the same constructor method signatures, so they can be constructed in the same way.

C#
// OktaClient is a convenience client to create other clients
var oktaClient = new OktaClient("your api token", "your production subdomain");
var usersClient = oktaClient.GetUsersClient();

// Or create clients directly
usersClient = new UsersClient("your api token", "your production subdomain");
Create a Client Against Another Environment

Connect to another environment (if available) to perform testing without affecting your production instance.

C#
var oktaClient = new OktaClient("your api token", new Uri("https://your_subdomain.oktapreview.com"));
Create a Client With a Proxy

Using OktaSettings, we can use a proxy to connect to Okta.

C#
var handler = new HttpClientHandler()
{
    Proxy = new WebProxy(new Uri("http://your_proxy")),
    UseProxy = true
};

var oktaSettings = new OktaSettings()
{
    ApiToken = "your api token",
    Subdomain = "your production subdomain",
    CustomHttpHandler = handler
};

var oktaClient = new OktaClient(oktaSettings);
CRUD Operations

Perform simple CRUD operations in Okta. The User entity is our example, but the concepts extend to most OktaObjects.

C#
var usersClient = new UsersClient("your api token", "your production subdomain");

var user = new User("newuser@example.com", "newuser@example.com", "New", "User");

// Create and activate the user
user = usersClient.Add(user);

// Retrieve the user
user = usersClient.Get("newuser@example.com");

// Update the user's first name
user.Profile.FirstName = "Old";
user = usersClient.Update(user);

// Deactivate the user (this is Remove on most OktaObjects)
usersClient.Deactivate(user);
Enumeration

Loop through a list of OktaObjects.

C#
var usersClient = new UsersClient("your api token", "your production subdomain");

for(var user in usersClient)
{
    // Do something with each user
}
Paged Enumeration

Loop through a list of OktaObjects while controlling pagination.

C#
var usersClient = new UsersClient("your api token", "your production subdomain");

// Loop through pages, 100 users at a time
Uri nextPage = null;
PagedResults<User> users;

do
{
    users = usersClient.GetList(pageSize: 100, nextPage: nextPage);

    foreach (var user in users.Results)
    {
        // Do something with each user
    }

    nextPage = users.NextPage;
}
while (!users.IsLastPage);
Filtered Enumeration

Loop through a list of OktaObjects with a filter applied.

C#
var usersClient = new UsersClient("your api token", "your production subdomain");

var filter = new FilterBuilder()
                .Where(Filters.User.Status)
                .EqualTo(UserStatus.Active)
                .And()
                .Where(Filters.User.LastUpdated)
                .GreaterThanOrEqual(new DateTime(2014, 1, 1));

foreach (User user in usersClient.GetFilteredEnumerator(filter))
{
    // Do something with each user
}
Get Custom Properties

Universal Directory enables the ability to add properties that aren't mapped to an object.

C#
var usersClient = new UsersClient("your api token", "your production subdomain");

var user = usersClient.Get("user_with_custom_attributes@your_org.com");

string custom = user.GetProperty("custom_attribute");

user.SetProperty("custom_attribute", "new_value");