Skip to content

authdog/sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

220 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Authdog SDK

Official SDKs for Authdog authentication and user management platform.

SDK Health Status

Python SDK Tests Node.js SDK Tests Go SDK Tests Java SDK Tests C# SDK Tests C++ SDK Tests Kotlin SDK Tests Rust SDK Tests PHP Tests Elixir Tests Scala Tests Clojure Tests Common Lisp Tests Swift Tests Zig Tests F# SDK OCaml SDK PowerShell SDK Dart SDK C SDK

Available SDKs

Core SDKs

Planned SDKs

These SDKs are in the planned/ directory and are not yet production-ready.

Quick Start Examples

Python SDK

Python SDK Tests

from authdog import AuthdogClient

# Initialize the client
client = AuthdogClient("https://api.authdog.com")

# Get user information
user_info = client.get_userinfo("your-access-token")
print(f"User: {user_info['user']['displayName']}")

# Always close the client
client.close()

Node.js SDK

Node.js SDK Tests

import { AuthdogClient } from '@authdog/node-sdk';

// Initialize the client
const client = new AuthdogClient({
  baseUrl: 'https://api.authdog.com'
});

// Get user information
const userInfo = await client.getUserInfo('your-access-token');
console.log(`User: ${userInfo.user.displayName}`);

Go SDK

Go SDK Tests

package main

import (
    "context"
    "fmt"
    "log"
    
    "github.com/authdog/go-sdk"
)

func main() {
    // Initialize the client
    client := authdog.NewClient(authdog.ClientConfig{
        BaseURL: "https://api.authdog.com",
        APIKey:  "your-api-key", // Optional
    })

    // Get user information
    ctx := context.Background()
    userInfo, err := client.GetUserInfo(ctx, "your-access-token")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("User: %s\n", userInfo.User.DisplayName)
}

Kotlin SDK

Kotlin SDK Tests

import com.authdog.sdk.*
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
    // Initialize the client
    val client = AuthdogClient(
        AuthdogClientConfig(
            baseUrl = "https://api.authdog.com",
            apiKey = "your-api-key" // Optional
        )
    )

    // Get user information
    val userInfo = client.getUserInfo("your-access-token")
    println("User: ${userInfo.user.displayName}")
}

Rust SDK

Rust SDK Tests

use authdog::{AuthdogClient, AuthdogClientConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the client
    let config = AuthdogClientConfig {
        base_url: "https://api.authdog.com".to_string(),
        api_key: Some("your-api-key".to_string()), // Optional
        ..Default::default()
    };
    
    let client = AuthdogClient::new(config)?;

    // Get user information
    let user_info = client.get_user_info("your-access-token").await?;
    println!("User: {}", user_info.user.display_name);

    Ok(())
}

PHP SDK

PHP Tests

<?php

require_once 'vendor/autoload.php';

use Authdog\AuthdogClient;
use Authdog\Exceptions\AuthenticationException;
use Authdog\Exceptions\ApiException;

// Initialize the client
$client = new AuthdogClient('https://api.authdog.com');

try {
    // Get user information
    $userInfo = $client->getUserInfo('your-access-token');
    echo "User: " . $userInfo->user->displayName . "\n";
} catch (AuthenticationException $e) {
    echo "Authentication failed: " . $e->getMessage() . "\n";
} catch (ApiException $e) {
    echo "API error: " . $e->getMessage() . "\n";
}

// Always close the client
$client->close();

C# SDK

C# SDK Tests

using Authdog;
using Authdog.Exceptions;

// Initialize the client
var client = new AuthdogClient("https://api.authdog.com");

try
{
    // Get user information
    var userInfo = await client.GetUserInfoAsync("your-access-token");
    Console.WriteLine($"User: {userInfo.User.DisplayName}");
}
catch (AuthenticationException ex)
{
    Console.WriteLine($"Authentication failed: {ex.Message}");
}
catch (ApiException ex)
{
    Console.WriteLine($"API error: {ex.Message}");
}
finally
{
    // Always dispose the client
    client.Dispose();
}

C++ SDK

C++ SDK Tests

#include <iostream>
#include "authdog/authdog_client.h"
#include "authdog/exceptions.h"

int main() {
    try {
        // Initialize the client
        authdog::AuthdogClient client("https://api.authdog.com");
        
        // Get user information
        auto userInfo = client.getUserInfo("your-access-token");
        std::cout << "User: " << userInfo.user.displayName << std::endl;
        
        // Close the client
        client.close();
        
    } catch (const authdog::AuthenticationException& e) {
        std::cerr << "Authentication failed: " << e.what() << std::endl;
    } catch (const authdog::ApiException& e) {
        std::cerr << "API error: " << e.what() << std::endl;
    }
    
    return 0;
}

Elixir SDK

Elixir Tests

# Initialize the client
client = Authdog.Client.new("https://api.authdog.com")

# Get user information
case Authdog.Client.get_user_info(client, "your-access-token") do
  {:ok, user_info} ->
    IO.puts("User: #{user_info.user.display_name}")
  {:error, :authentication_error, message} ->
    IO.puts("Authentication failed: #{message}")
  {:error, :api_error, message} ->
    IO.puts("API error: #{message}")
end

Java SDK

Java SDK Tests

import com.authdog.AuthdogClient;
import com.authdog.exceptions.AuthenticationException;
import com.authdog.exceptions.ApiException;

// Initialize the client
try (AuthdogClient client = new AuthdogClient("https://api.authdog.com")) {
    // Get user information
    UserInfoResponse userInfo = client.getUserInfo("your-access-token");
    System.out.println("User: " + userInfo.getUser().getDisplayName());
} catch (AuthenticationException e) {
    System.err.println("Authentication failed: " + e.getMessage());
} catch (ApiException e) {
    System.err.println("API error: " + e.getMessage());
}

Scala SDK

Scala Tests

import com.authdog.AuthdogClient
import com.authdog.exceptions.{AuthenticationException, ApiException}

// Initialize the client
val client = AuthdogClient("https://api.authdog.com")

try {
  // Get user information
  val userInfo = client.getUserInfo("your-access-token")
  println(s"User: ${userInfo.user.displayName}")
} catch {
  case e: AuthenticationException => 
    println(s"Authentication failed: ${e.getMessage}")
  case e: ApiException => 
    println(s"API error: ${e.getMessage}")
} finally {
  client.close()
}

Common Lisp SDK

Common Lisp Tests

(ql:quickload :authdog)
(use-package :authdog)

;; Initialize the client
(defvar *client* (make-authdog-client "https://api.authdog.com"))

;; Get user information
(handler-case
    (let ((user-info (get-user-info *client* "your-access-token")))
      (format t "User: ~A~%" (user-display-name (user-info-response-user user-info))))
  (authentication-error (e)
    (format t "Authentication failed: ~A~%" (authdog-error-message e)))
  (api-error (e)
    (format t "API error: ~A~%" (authdog-error-message e))))

Clojure SDK

Clojure Tests

(require '[authdog.core :as authdog]
         '[authdog.exceptions :as ex])

;; Initialize the client
(def client (authdog/make-client "https://api.authdog.com"))

;; Get user information
(try
  (let [user-info (authdog/get-user-info client "your-access-token")]
    (println "User:" (:display-name (:user user-info))))
  (catch clojure.lang.ExceptionInfo e
    (cond
      (ex/authentication-error? e)
      (println "Authentication failed:" (.getMessage e))
      
      (ex/api-error? e)
      (println "API error:" (.getMessage e)))))

Swift SDK

Swift Tests

import AuthdogSwiftSDK

// Initialize the client
let client = AuthdogClient(baseURL: "https://api.authdog.com")

// Get user information (async/await)
Task {
    do {
        let userInfo = try await client.getUserInfo(accessToken: "your-access-token")
        print("User: \(userInfo.user.displayName)")
    } catch AuthdogError.authenticationFailed(let message) {
        print("Authentication failed: \(message)")
    } catch AuthdogError.apiError(let message) {
        print("API error: \(message)")
    }
}

// Get user information (completion handler)
client.getUserInfo(accessToken: "your-access-token") { result in
    switch result {
    case .success(let userInfo):
        print("User: \(userInfo.user.displayName)")
    case .failure(let error):
        print("Error: \(error.localizedDescription)")
    }
}

Zig SDK

Zig Tests

const authdog = @import("authdog");

// Initialize the client
var client = authdog.AuthdogClient.init("https://api.authdog.com", .{});

// Get user information
const user_info = client.getUserInfo("your-access-token") catch |err| switch (err) {
    error.AuthenticationFailed => {
        std.debug.print("Authentication failed\n", .{});
        return;
    },
    error.ApiError => {
        std.debug.print("API error\n", .{});
        return;
    },
    else => {
        std.debug.print("Unexpected error: {}\n", .{err});
        return;
    },
};

std.debug.print("User: {s}\n", .{user_info.user.display_name});

Additional SDKs

F# SDK OCaml SDK PowerShell SDK Dart SDK

These SDKs are also available with full documentation in their respective directories.

Features

  • User Information: Get detailed user information including profile data, emails, photos, and verification status
  • Authentication: Handle authentication errors and token validation
  • Type Safety: Full type support across all languages (TypeScript, Go, Kotlin, Rust)
  • Error Handling: Structured error handling with specific exception types
  • Modern APIs: Built with modern HTTP clients and async/await support
  • Cross-Platform: Core SDKs for Python, Node.js, Go, Rust, Java, and C#. Additional planned SDKs in planned/

API Endpoints

All SDKs support the following endpoint:

GET /v1/userinfo

Retrieve user information using an access token.

Authentication: Bearer token required

Response Structure:

{
  "meta": {
    "code": 200,
    "message": "Success"
  },
  "session": {
    "remainingSeconds": 56229
  },
  "user": {
    "id": "user-id",
    "externalId": "external-id",
    "userName": "username",
    "displayName": "Display Name",
    "emails": [{"value": "email@example.com", "type": null}],
    "photos": [{"value": "https://example.com/photo.jpg", "type": "photo"}],
    "names": {
      "familyName": "Last",
      "givenName": "First"
    },
    "verifications": [...],
    "provider": "google-oauth20",
    "environmentId": "env-id"
  }
}

Error Handling

All SDKs provide structured error handling:

  • AuthenticationError: Raised when authentication fails (401 responses)
  • APIError: Raised when API requests fail
  • Base AuthdogError: Common base class for all SDK errors

Development

Prerequisites

This monorepo uses moonrepo (moon) for task orchestration and caching, and proto for toolchain version management.

Install proto and moon:

# Install proto (toolchain manager)
curl -fsSL https://moonrepo.dev/install/proto.sh | bash

# Install moon (task runner)
curl -fsSL https://moonrepo.dev/install/moon.sh | bash

# Install pinned language toolchains from .prototools
proto use

Proto manages Node.js 20.18.0, pnpm 9.15.0, Go 1.21.13, Rust 1.82.0, and Python 3.11.10. Java and C# require manual installation (via SDKMAN, setup-java, etc.).

Running tasks with moon

Moon orchestrates builds, tests, and linting across all 6 core SDKs with intelligent caching — unchanged tasks are skipped on subsequent runs.

# Run all checks across all projects
moon check --all

# Run a specific task for a specific SDK
moon run python:test
moon run node:build
moon run go:lint
moon run rust:fmt
moon run java:test
moon run csharp:build

# Run tests for all SDKs
moon run :test

Available tasks per SDK

Task Python Node Go Rust Java C#
deps pip install pnpm install go mod download mvn dependency:resolve dotnet restore
test pytest pnpm run test:coverage go test cargo test mvn test dotnet test
lint flake8 pnpm run lint go vet cargo clippy mvn checkstyle:check dotnet format
build python -m build pnpm run build go build cargo build mvn compile dotnet build
fmt gofmt cargo fmt
security cargo audit security-scan
benchmark go test -bench mvn test (JMH)

Caching

Moon provides 3 tiers of caching:

  1. Moon task cache (.moon/cache/) — skips entire task re-execution when inputs are unchanged
  2. Proto tool cache (~/.proto/tools/) — avoids re-downloading language runtimes
  3. Language dependency caches (go modules, cargo registry, maven, nuget) — avoids re-downloading packages

CI

All 6 core SDK workflows use a shared composite action that installs proto + moon and restores caches. Multi-version matrix jobs (e.g., Go 1.20, Rust beta/nightly) use native setup-* actions directly since proto pins a single version.

Adding a new SDK to moon

  1. Create a moon.yml in the SDK directory defining tasks
  2. Add the project to .moon/workspace.yml
  3. Update the corresponding GitHub Actions workflow to use the setup-moon action
  4. For proto-supported languages, add the version to .prototools

Individual SDK development

Each SDK also has its own README with SDK-specific setup instructions:

Contributing

Please see our Contributing Guide for details on how to contribute to the SDKs.

License

MIT License - see LICENSE for details.

About

self-explanatory

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors