Giter VIP home page Giter VIP logo

corbado-go's Introduction

GitHub Repo Cover

Corbado Go SDK

Go Reference License: MIT Test Status Go Report Card documentation Slack

The Corbado Go SDK provides convenient access to the Corbado Backend API from applications written in the Go language.

⚠️ The Corbado Go SDK is commonly referred to as a private client, specifically designed for usage within closed backend applications. This particular SDK should exclusively be utilized in such environments, as it is crucial to ensure that the API secret remains strictly confidential and is never shared.

🚀 Getting started | 🛠️ Services | 📚 Advanced | 💬 Support & Feedback

🚀 Getting started

Requirements

  • Go 1.18 or later

Installation

Use the following command to install the Corbado Go SDK:

go get github.com/corbado/[email protected]

Usage

To create a Corbado Go SDK instance you need to provide your Project ID and API secret which can be found at the Developer Panel.

package main

import (
    "github.com/corbado/corbado-go"
)

func main() {
    config, err := corbado.NewConfig("<Project ID>", "<API secret>")
    if err != nil {
        panic(err)
    }

    sdk, err := corbado.NewSDK(config)
    if err != nil {
        panic(err)
    }
}

Examples

A list of examples can be found in the examples directory. Integration tests are good examples as well.

🛠️ Services

The Corbado Go SDK provides the following services:

  • AuthTokens for managing authentication tokens needed for own session management (examples)
  • EmailMagicLinks for managing email magic links (examples)
  • EmailOTPs for managing email OTPs (examples)
  • Sessions for managing sessions (examples)
  • SmsOTPs for managing SMS OTPs (examples)
  • Users for managing users (examples)
  • Validations for validating email addresses and phone numbers (examples)

To use a specific service, such as Users, invoke it as shown below:

users, err := sdk.Users().List(context.Background(), nil)
if err != nil {
    panic(err)
}

📚 Advanced

Error handling

The Corbado Go SDK uses Go standard error handling (error interface). If the Backend API returns a HTTP status code other than 200, the Corbado Go SDK returns a ServerError error (which implements the error interface):

package main

import (
    "context"
    "fmt"

    "github.com/corbado/corbado-go"
)

func main() {
    config, err := corbado.NewConfig("<Project ID>", "<API secret>")
    if err != nil {
        panic(err)
    }

    sdk, err := corbado.NewSDK(config)
    if err != nil {
        panic(err)
    }

    // Try to get non-existing user with ID 'usr-123456789'
    user, err := sdk.Users().Get(context.Background(), "usr-123456789", nil)
    if err != nil {
        if serverErr := corbado.AsServerError(err); serverErr != nil {
            // Show HTTP status code (404 in this case)
            fmt.Println(serverErr.HTTPStatusCode)

            // Show request ID (can be used in developer panel to look up the full request
            // and response, see https://app.corbado.com/app/logs/requests)
            fmt.Println(serverErr.RequestData.RequestID)

            // Show runtime of request in seconds (server side)
            fmt.Println(serverErr.Runtime)

            // Show validation error messages (server side validation in case of HTTP
            // status code 400 (Bad Request))
            fmt.Printf("%+v\n", serverErr.Validation)
        } else {
            // Handle other errors
            panic(err)
        }

        return
    }

    fmt.Println(user.Data.ID)
}

💬 Support & Feedback

Report an issue

If you encounter any bugs or have suggestions, please open an issue.

Slack channel

Join our Slack channel to discuss questions or ideas with the Corbado team and other developers.

Slack

Email

You can also reach out to us via email at [email protected].

Vulnerability reporting

Please report suspected security vulnerabilities in private to [email protected]. Please do NOT create publicly viewable issues for suspected security vulnerabilities.

corbado-go's People

Contributors

corbadoman avatar corbadovych avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

lcarilla

corbado-go's Issues

Improve SDK

  • Copy and adapt README from corbado-php
  • Run all code examples from README (make sure they are working)
  • Make all code examples fully working (imports, fun main etc.)
  • Adapt corbado-php directory structure (introduce services etc.)
  • Move config to root and rename to Configuration
  • Set version 1.0.0
  • Add more Go versions to GitHub matrix (until test users have been implemented)
  • Use test users (for email OTP and sms OTP)
  • Implement integration test for email OTP validate and sms OTP validate
  • Update documentation
  • Update wizards
  • Restructure version header (rename to X-Corbado-SDK, add "name", "sdkVersion" and "languageVersion" to it)
  • Move internal packages to internal/
  • Extend README.md with "private client" info

The Corbado GO SDK is commonly referred to as a private client, specifically designed for usage within closed backend applications. This particular SDK should exclusively be utilized in such environments, as it is crucial to ensure that the API secret remains strictly confidential and is never shared.

Add SDK version to every request

Why

To get a understanding what SDKs our customers use we need to provide the SDK version in every API request.

TODOS

  • Add release version to go binary in some version constant/variable
  • Add this version to every request as an additional header: X-Corbado-SDK-Version (we use an additional header because we need to preserve the User-Agent field for the real user agent of the user of our customer)
  • Value: "Go SDK (release version)" so for example "Go SDK v0.3.0"

Competitors

Bugs in v3.0.0

  • MIT license links to PHP
  • Change integration test email

Add system tests

  • Make real calls to the production BackendAPI
    • Add a new project, name “Corbado Go SDK System testing” (so each SDK will have its on corresponding project)
    • Should be same user/owner as Corbado
  • Use GitHub Secrets
    • CORBADO_BACKENDAPI
    • CORBADO_PROJECT_ID
    • CORBADO_APISECRET
  • Always use “random values” for fields with unique constraints so system tests can always run in parallel
  • Always “clean up” everything after system tests so system tests can run multiple times (and the project stays clean)

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.