![GitHub Repo Cover](https://private-user-images.githubusercontent.com/18458907/291711345-aa4f9df6-980b-4b24-bb2f-d71c0f480971.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyOTY5NzIsIm5iZiI6MTcyNDI5NjY3MiwicGF0aCI6Ii8xODQ1ODkwNy8yOTE3MTEzNDUtYWE0ZjlkZjYtOTgwYi00YjI0LWJiMmYtZDcxYzBmNDgwOTcxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIyVDAzMTc1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU3YTdlYmRjZTMwZmM5MTc2YjVmNWE2ZjJjOWY0ZmJiMzhhODcwNDdhYjAxMWY4NmU3MWY4NDhhMmVlZDQ3NmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.sewdVFKQcu4DcH5wlmJpIMFZ8FQlWPppAo0ksRvgBPk)
The Corbado Go SDK provides convenient access to the Corbado Backend API from applications written in the Go language.
🚀 Getting started | 🛠️ Services | 📚 Advanced | 💬 Support & Feedback
- Go 1.18 or later
Use the following command to install the Corbado Go SDK:
go get github.com/corbado/[email protected]
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)
}
}
A list of examples can be found in the examples directory. Integration tests are good examples as well.
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)
}
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)
}
If you encounter any bugs or have suggestions, please open an issue.
Join our Slack channel to discuss questions or ideas with the Corbado team and other developers.
You can also reach out to us via email at [email protected].
Please report suspected security vulnerabilities in private to [email protected]. Please do NOT create publicly viewable issues for suspected security vulnerabilities.