Code Example Authentication - Implan-Group/api GitHub Wiki

Code Example - Authentication

The following are examples of Authentication to the Impact API using various different programming languages.


C#

// create a new HttpClient to make the Request
using var client = new HttpClient();  
// setup your Implan credentials
var credentials = new Credentials  
{  
    Username = "{username}",  
    Password = "{password}"  
};  
// POST the request to the auth endpoint  
using var response = await client.PostAsJsonAsync("https://api.implan.com/api/auth", credentials);  
// the response wil be the bearer token in the form
// "Bearer {token}"
string token = await response.Content.ReadAsStringAsync();  
Console.WriteLine(token);

// need some class to hold the credentials  
public class Credentials  
{  
    public string Username { get; set; }  
    public string Password { get; set; }  
}

Python

import requests
from requests import Response

# The API Auth Endpoint
url: str = "https://api.implan.com/api/auth"

# Credentials to be sent
credentials: dict = {
    "username": "{username}",
    "password": "{password}"
}

# POST the request
response: Response = requests.post(url, json=credentials)

# The response will be 'Bearer {token}'
token: str = response.content.decode("utf-8")

print(token)

R

library(RCurl)
headers = c(
  "Content-Type" = "text/plain"
)
params = "{  \"username\": \"{username}\",   \"password\": \"{password}\" }\r\n"
res <- postForm("https://api.implan.com/api/auth", .opts=list(postfields = params, httpheader = headers, followlocation = TRUE), style = "httppost")
cat(res)

Java

Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://api.implan.com/api/auth")
  .header("Content-Type", "text/plain")
  .body("{  \"username\": \"\",   \"password\": \"\" }\r\n")
  .asString();

⚠️ **GitHub.com Fallback** ⚠️