Git Product home page Git Product logo

jcapi-go's Introduction

JCAPI-Go

Description

This repository contains the Go client code for the JumpCloud API v1 and v2. This code is automatically generated using Swagger Codegen. It also provides the tools to generate the client code from the API YAML files, using Swagger Codegen. For detailed instructions on how to generate the code, see the Contributing section.

To access our old API v1 Go client, please refer to JCAPI. However this code repository is not up to date with current API functionality.

Authentication and Authorization

All endpoints support authentication via API key: see the Authentication & Authorization section in our API documentation.

Some systems endpoints (in both API v1 and v2) also support System Context Authorization which allows an individual system to manage its information and resource associations.

Usage Examples

For more detailed instructions, refer to each API version's respective README file (README for API v1 and README for API v2) and the generated documentation under each folder.

API v2 Example

package main

import (
	"context"
	"fmt"

	jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2"
)

func main() {
	apiKey := "YOUR_API_KEY"
	userGroupID := "YOUR_GROUP_ID"

	contentType := "application/json"
	accept := "application/json"

	// Instantiate the API client
	client := jcapiv2.NewAPIClient(jcapiv2.NewConfiguration())

	// Set up the API key via context
	auth := context.WithValue(context.TODO(), jcapiv2.ContextAPIKey, jcapiv2.APIKey{
		Key: apiKey,
	})

	// Make an API call to retrieve a specific user group by ID
	userGroup, res, err := client.UserGroupsApi.GroupsUserGet(auth, userGroupID, contentType, accept, nil)
	if err != nil {
		fmt.Printf("Error retrieving user group %s: %s - response = %+v\n", userGroupID, err, res)
	} else {
		fmt.Printf("Details for User group %s: %+v\n", userGroupID, userGroup)
	}
}

System Context Authorization Example

package main

import (
	"context"
	"fmt"

	jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2"
)

func main() {
	// Set headers for System Context Authorization. For detailed instructions on
	// how to generate these headers, refer to:
	// https://docs.jumpcloud.com/2.0/authentication-and-authorization/system-context
	systemID := "YOUR_SYSTEM_ID"
	systemDate := "YOUR_SYSTEM_DATE" // The current date on the system, e.g. "Tue, 10 Nov 2009 23:00:00 GMT"
	systemSignature := "YOUR_SYSTEM_SIGNATURE"
	systemContextAuth := fmt.Sprintf(`Signature keyId="system/%s",headers="request-line date",algorithm="rsa-sha256",signature="%s"`, systemID, systemSignature)

	contentType := "application/json"
	accept := "application/json"

	// Instantiate the API client
	client := jcapiv2.NewAPIClient(jcapiv2.NewConfiguration())

	// Add date and authorization to the list of optional parameters
	optParams := map[string]interface{}{
		"date":          systemDate,
		"authorization": systemContextAuth,
	}

	// List the system groups this system is a member of using the
	// System Context Authorization parameters. Since we authenticate via the
	// parameters, there is no need to set the API key in the context.
	groups, res, err := client.SystemsApi.GraphSystemMemberOf(context.TODO(), systemID, contentType, accept, optParams)
	if err != nil {
		fmt.Printf("Error retrieving system groups for system %s: %s - response = %+v\n", systemID, err, res)
		return
	}

	// Print the system groups we just retrieved
	for _, group := range groups {
		fmt.Printf("System group ID %s\n", group.Id)
	}
}

jcapi-go's People

Contributors

tsmithjc avatar jcasey-jc avatar jpvajda avatar subhajit97 avatar alanghartjc avatar radduccijc avatar antonu17 avatar joshjumpcloud avatar lshupejc avatar sharvanek avatar pritchardtw avatar rmulley 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.