Skip to content

UrbanCompass/onelogin-go-sdk-compass

 
 

Repository files navigation

Compass Fork

Fixing the following issues:

  • Doesn't support pagination. Adding support for AfterCursor.
  • Errors when setting query parameters.

Onelogin Go SDK

This is the Onelogin SDK, a Go package that provides a convenient interface for interacting with Onelogin's API. The SDK simplifies the integration process by providing developers an easy-to-use tool for managing authentication, making API requests, and handling responses.

Features

  • Authentication: Obtain and revoke access tokens for authenticating API requests using environment variables.
  • API Requests: Construct and send requests to Onelogin's API.
  • Response Handling: Parse and handle API responses.
  • Error Management: Handle and recover from errors effectively.
  • Data Models: Represent Onelogin entities and resources.
  • Utilities: Provide utility functions and helper methods.

Supported APIs

Partially Support APIs

Installation

To use the Onelogin SDK in your Go project, you need to have Go installed and set up. Then, you can install the SDK using the go get command:

go get github.com/UrbanCompass/onelogin-go-sdk-compass

Requirements

The SDK expects three environment variables to be set for authentication:

  • ONELOGIN_CLIENT_ID
  • ONELOGIN_CLIENT_SECRET
  • ONELOGIN_SUBDOMAIN
  • ONELOGIN_TIMEOUT

These variables are used by the Authenticator for authentication with the OneLogin API. The Authenticator retrieves an access token using these credentials, which is then used for API requests. You can set these variables directly in your shell or in the environment of the program that will be using this SDK.

In a Unix/Linux shell, you can use the export command to set these variables:

export ONELOGIN_CLIENT_ID=your_client_id
export ONELOGIN_CLIENT_SECRET=your_client_secret
export ONELOGIN_SUBDOMAIN=your_subdomain
export ONELOGIN_TIMEOUT=15

In a Go program, you can use the os package to set these variables:

os.Setenv("ONELOGIN_CLIENT_ID", "your_client_id")
os.Setenv("ONELOGIN_CLIENT_SECRET", "your_client_secret")
os.Setenv("ONELOGIN_SUBDOMAIN", "your_subdomain")
os.Setenv("ONELOGIN_TIMEOUT", 15)

Please ensure these variables are set before attempting to use the SDK to make API requests.

Usage

Here's an example demonstrating how to use the Onelogin SDK:

package main

import (
 "fmt"

 "github.com/UrbanCompass/onelogin-go-sdk-compass/v4/pkg/onelogin/models"
 "github.com/UrbanCompass/onelogin-go-sdk-compass/v4/pkg/onelogin"
)

func main() {
 ol, err := onelogin.NewOneloginSDK()
 if err != nil {
  fmt.Println("Unable to initialize client:", err)
  return
 }
 userQuery := models.UserQuery{}
 userList, err := ol.GetUsers(&userQuery)
 if err != nil {
  fmt.Println("Failed to get user:", err)
  return
 }
 fmt.Println(userList)

 appQuery := models.AppQuery{}
 appList, err := ol.GetApps(&appQuery)
 if err != nil {
  fmt.Println("Failed to get app list:", err)
  return
 }
 fmt.Println("App List:", appList)
}

Documentation

Comprehensive documentation for the Onelogin SDK is available in the docs directory. The following documents provide detailed information on using the SDK and its various modules:

  • api.md: Documentation for the API module, including request construction, communication, and response handling.
  • authentication.md: Detailed documentation for the Authentication module, including the process of obtaining and revoking access tokens as well as retrieving the token for other applications or services.
  • error_handling.md: Documentation for error handling, including information on error types and codes.
  • index.md: Introduction and overview of the SDK, including goals and architecture.
  • models.md: Documentation for the models module, describing the data models that represent Onelogin entities and resources.
  • usage_examples.md: Contains usage examples and code snippets demonstrating various SDK functionalities.

Contributing

Contributions to the Onelogin SDK are welcome! If you encounter any issues or have suggestions for improvement, please open an issue or submit a pull request. We appreciate your feedback and contributions.