Git Product home page Git Product logo

okta-sdk-java's Introduction

Maven Central License Support

okta-sdk-java

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

This version of the Okta Java SDK supports CRUD (Create, Read, Update, Delete) operations for the following resource:

  • User
  • Group
  • Group Membership Rules

Usage

Javadocs

You can see this project's Javadocs at https://developer.okta.com/okta-sdk-java/apidocs/.

Dependencies

The only compile time dependency you will need is okta-sdk-api. You will also need to add the implementation dependencies too: okta-sdk-impl and okta-sdk-httpclient.

<dependency>
    <groupId>com.okta.sdk</groupId>
    <artifactId>okta-sdk-api</artifactId>
    <version>${okta.version}</version>
</dependency>
<dependency>
    <groupId>com.okta.sdk</groupId>
    <artifactId>okta-sdk-impl</artifactId>
    <version>${okta.version}</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>com.okta.sdk</groupId>
    <artifactId>okta-sdk-httpclient</artifactId>
    <version>${okta.version}</version>
    <scope>runtime</scope>
</dependency>

SNAPSHOT Dependencies

Snapshots are deployed off of the 'master' branch to OSSRH and can be consumed using the following repository configured for Apache Maven or Gradle:

https://oss.sonatype.org/content/repositories/snapshots/

Client configuration

There are a few ways to configure the client, but the easiest way is to create a ~/.okta/okta.yamlfile and set the token and orgUrl values:

okta:
  client:
    token: <your-api-token>
    orgUrl: https://dev-123456.oktapreview.com

Creating a Client

Once you create your okta.yaml file, you can create a client with a couple of lines:

// Instantiate a builder for your Client. If needed, settings like Proxy and Caching can be defined here.
ClientBuilder builder = Clients.builder();

// No need to define anything else; build the Client instance. The ClientCredential information will be automatically found
// in pre-defined locations.
Client client = builder.build();

For more details see: Creating a Client

Client CRUD Operations

The client is used to perform CRUD operations against Okta's management APIs.

Create a group:

UserGroup group = GroupBuilder.instance()
        .setName("my-user-group-" + UUID.randomUUID().toString())
        .setDescription("Quickstart created Group")
        .buildAndCreate(client);

// print a couple of the attributes
println("Group: '" + group.getId() + "' was last updated on: " + group.getLastUpdated());

Create a User Account:

String email = "joe.coder+" + UUID.randomUUID().toString() + "@example.com";

User user = UserBuilder.instance()
    .setEmail(email)
    .setFirstName("Joe")
    .setLastName("Coder")
    .setPassword("Password1")
    .setSecurityQuestion("Favorite security question?")
    .setSecurityQuestionAnswer("None of them!")
    .putProfileProperty("division", "Seven") // key/value pairs predefined in the user profile schema
    .setActive(true)
    .buildAndCreate(client);

String userId = user.getId();
println("User created with ID: " + userId);

Add user to the newly created group:

user.addToGroup(group.getId());

User lookup by ID or email:

// You can look up user by ID
println("User lookup by ID: "+ client.getUser(userId).getProfile().getLogin());

// or by Email
println("User lookup by Email: "+ client.getUser(email).getProfile().getLogin());

Paging

Paging is handled automatically when iterating over a any collection.

// get the list of users
UserList users = client.listUsers();

// get the first user in the collection
println("First user in collection: " + users.iterator().next().getProfile().getEmail());

// or loop through all of them (paging is automatic)
int ii = 0;
for (User tmpUser : users) {
    println("["+ ii++ +"] User: " + tmpUser.getProfile().getEmail());
}

Contribute to the Project

Take a look at the (contribution guide)[CONTRIBUTING.md] and the build instructions wiki (though just cloning the repo and running mvn install should get you going).

okta-sdk-java's People

Contributors

bdemers avatar lboyette-okta avatar jmelberg-okta avatar hrishikeshsathe-okta avatar alainodea avatar joelfranusic-okta avatar senthilkumaran-okta avatar tthompson-okta avatar ashishgupta-okta avatar guyzehavi-okta avatar jmaldonado-okta avatar gabrielsroka avatar orsenthil avatar dogeared avatar larsjohansen-okta avatar irasekh3 avatar hales-zillow avatar brianzuzga-okta avatar alain-odea-vgh 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.