Git Product home page Git Product logo

oktasdk-java's Introduction

oktasdk-java

This SDK is in EA, so all existing features are supported by Okta in a production setting

To build and install:

  1. Clone the repo
  2. Navigate to the repo directory. It should contain pom.xml
  3. Build with tests mvn install or without tests mvn -Dmaven.test.skip=true install

###Client configuration

import com.okta.sdk.framework.ApiClientConfiguration;

ApiClientConfiguration oktaSettings = new ApiClientConfiguration(
                                        "https://your_org.okta.com",
                                        "your_api_key");

###AuthApiClient This client is used to authenticate and validate user credentials. Information about the various states of authentication are available at http://developer.okta.com/docs/api/resources/authn.html

AuthApiClient authClient = new AuthApiClient(oktaSettings);

// Check if the user credentials are valid
AuthResult result = authClient.authenticate(username, password, someRelayState);
// The result has a getStatus method which is a string of status of the request.
// Example - SUCCESS for successful authentication
String status = result.getStatus();

###UserApiClient and CRUD This client is used to perform CRUD operations on user objects (http://developer.okta.com/docs/api/resources/users.html).

UserApiClient userApiClient = new UserApiClient(oktaSettings);

// Create a new user
// First Name, Last Name, Email and Login are required. Password is optional.
// The boolean variable is for activate which means that activate the user as soon as 
// it is created.
User newUser = userApiClient.createUser(
                "First",
                "Last",
                "[email protected]",
                "[email protected]",
                true);

// Create a new user with a password.
// For this you need to create a UserProfile object and a LoginCredentials object
UserProfile userProfile = new UserProfile();
userProfile.setFirstName("First");
userProfile.setLastName("Last");
userProfile.setEmail("[email protected]");
userProfile.setLogin("[email protected]");

LoginCredentials loginCredentials = new LoginCredentials();
Password password = new Password();
password.setValue("Password");
loginCredentials.setPassword(password);

User user = new User();
user.setProfile(userProfile);
user.setCredentials(loginCredentials);

// true is for activate user as soon as it is created
userApiClient.createUser(user, true);

// Read/Search
// There are plenty of methods for reading users.
// 1. Search user when user ID/loginName/loginShortName is known
User user = userApiClient.getUser("ID/loginName/loginShortName");

// 2. Search user using filters. You can query the API for searching a user
// with the help of filters mentioned at - http://developer.okta.com/docs/api/resources/users.html#filters
// Example - search for first name. Returns a list of users matching that query
FilterBuilder filterBuilder = new FilterBuilder("profile.firstName eq \"" + firstName + "\"");
List<User> users = userApiClient.getUsersWithFilter(filterBuilder);

// 3. Advanced search provides the option to filter on any user profile attribute, any custom defined
// profile attribute, as well as the following top-level attributes: id, status, created, activated, 
// statusChanged and lastUpdated. The advanced search performs a case insensitive filter against all fields
// specified in the search parameter. Note that the results might not yet be up to date, as the most up to date
// data can be delayed up to a few seconds, so use for convenience.
FilterBuilder filterBuilder = new FilterBuilder("profile.flightNumber eq \"A415\"");
List<User> users = userApiClient.getUsersWithSearch(filterBuilder);

// 4. Search users only on firstName, lastName or email
// The parameter passed is searched in the attributes - firstName, lastName and email of all Users.
List<User> users = userApiClient.getUsersWithQuery("firstName/lastName/email");

// Update
newUser.getProfile().setLastName("NewLast");
userApiClient.updateUser(newUser);

// Delete (for Users this is the same as deactivate)
userApiClient.deleteUser(newUser.getId());

###Paging

PagedResults<User> pagedResults = userApiClient.getUsersPagedResultsWithLimit(10);

while (true) {
    for (User user : pagedResults.getResult()) {
        // Do something with user
    }
    
    if (!pagedResults.isLastPage()) {
        pagedResults = userApiClient.getUsersPagedResultsByUrl(pagedResults.getNextUrl());
    } else {
        break;
    }
}

oktasdk-java's People

Contributors

lboyette-okta avatar hrishikeshsathe-okta avatar senthilkumaran-okta avatar tthompson-okta avatar irasekh3 avatar larsjohansen-okta avatar orsenthil avatar jmaldonado-okta avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.