Skip to content

Softheon/EnterpriseAPIClients

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Softheon Enterprise API Client Libraries

A collection of libraries for the Softheon Enterprise API. Client libraries are available in the following languages:

To get started using the Softheon Enterprise API, please visit https://hack.softheon.io. Please also visit the documentation site for more information on how to use the Softheon Enterprise API.

Overview

Client libraries are generated using the AutoRest open-source REST API client generation tool. The input to AutoRest is a spec file that describes the Softheon Enterprise API using the OpenAPI Specification. Swashbuckle was used for spec file generation.

Getting Started

The client libraries for each language includes all request and response models used by the Softheon Enterprise API, as well as methods covering all types of interactions supported by the Softheon Enterprise API. To get started using the client libraries, create an application using your IDE of choice. Then import the files located in the folder for your selected languge into your application.

C# Client Example

For an example on how to use a C# generated client, please refer to the AutoRest C# client documentation.

Client Runtimes

Some languages requrie additional client runtimes in order to use these libraries. Information on required client runtimes can be found in the AutoRest client runtime documentation.

Authentication

In order to make requests to the Softheon Enterprise API, you must include the Authorization request header with an OAuth 2.0 access token.

Access tokens are provided by the Softheon Identity authorization server. To obtain an access token, set the Content-Type to application/x-www-form-urlencoded. In the request body set grant_type to password and set the scope to enterpriseapi openid. Set the client_id and client_secret to your application's client id and client secret. Lastly, set the username and password to the username and password provided to you on the Softheon hack user card.

For more information on requesting access tokens, please refer to the Softheon Enterprise API OAuth 2 documentation.

C# Example

var client = new RestClient("https://hack.softheon.io/oauth2/connect/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("undefined", "grant_type=password&scope=enterpriseapi%20openid&client_id=<client id>&client_secret=<client secret>&username=<username>&password=<password>", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Go Example

package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://hack.softheon.io/oauth2/connect/token"

	payload := strings.NewReader("grant_type=password&scope=enterpriseapi%20openid&client_id=client_id=<client id>&client_secret=<client secret>&username=<username>&password=<password>")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}

Java Example

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "grant_type=password&scope=enterpriseapi%20openid&client_id=<client id>&client_secret=<client secret>&username=<username>&password=<password>");
Request request = new Request.Builder()
  .url("https://hack.softheon.io/oauth2/connect/token")
  .post(body)
  .addHeader("Content-Type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();();

Node.js Example

var qs = require("querystring");
var http = require("https");

var options = {
  "method": "POST",
  "hostname": [
    "hack",
    "softheon",
    "io"
  ],
  "path": [
    "oauth2",
    "connect",
    "token"
  ],
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(qs.stringify({ grant_type: 'password',
  scope: 'enterpriseapi openid',
  client_id: '<client id>',
  client_secret: '<client secret>',
  username: '<username>',
  password: '<password>' }));
req.end();

Python Example

import http.client

conn = http.client.HTTPConnection("hack,softheon,io")

payload = "grant_type=password&scope=enterpriseapi%20openid&client_id=<client id>&client_secret=<client secret>&username=<username>&password=<password>"

headers = {
    'Content-Type': "application/x-www-form-urlencoded",
    }

conn.request("POST", "oauth2,connect,token", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

Ruby Example

require 'uri'
require 'net/http'

url = URI("https://hack.softheon.io/oauth2/connect/token")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "grant_type=password&scope=enterpriseapi%20openid&client_id=<client id>&client_secret=<client secret>&username=<username>&password=<password>"

response = http.request(request)
puts response.read_body

PHP Example

<?php

$request = new HttpRequest();
$request->setUrl('https://hack.softheon.io/oauth2/connect/token');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'Content-Type' => 'application/x-www-form-urlencoded'
));

$request->setContentType('application/x-www-form-urlencoded');
$request->setPostFields(array(
  'grant_type' => 'password',
  'scope' => 'enterpriseapi openid',
  'client_id' => '<client id>',
  'client_secret' => '<client secret>',
  'username' => '<username>',
  'password' => '<password>'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

Acknowledgements

The Softheon Enterpise API client libraries are built using the following great open source projects