Get Started

Reference for the Magic Admin SDK for Golang: https://github.com/magiclabs/magic-admin-go

Overview

The Magic SDK for server-side Golang makes it easy to leverage Decentralized ID Tokens to authenticate your users for your app. This guide will cover some important topics for getting started with server-side APIs and to make the most of Magic's features.

  • Install the Magic Admin SDK to get started

  • View the API documentation below to learn the methods you'll be using

  • Go to Examples for an introduction to common patterns and use-cases

note

Looking for a client-side API instead? Check out:

๐Ÿ‘‰ Magic Client SDK for web

๐Ÿ‘‰ Magic Client SDK for React Native

Installation

The SDK requires Golang 1.13+ and Go Modules. To make sure your project is using Go Modules, you can look for go.mod file in your project's root directory. If it exits, then you are already using the Go Modules. If not, you can follow this guide to migrate to Go Modules.

Simply reference magic-admin-go in a Go program with an import of the SDK:

import (
...
"github.com/magiclabs/magic-admin-go"
...
)

Run any of the normal go commands (ex: build/install). The Go toolchain will take care of fetching the SDK automatically.

Alternatively, you can explicitly go get the package into a project:

go get github.com/magiclabs/magic-admin-go

Creating an SDK Client Instance

The Client handles all the Magic API requests for your application. To instantiate:

package main
import (
"github.com/magiclabs/magic-admin-go"
"github.com/magiclabs/magic-admin-go/client"
)
func main() {
m := client.New("<YOUR_API_SECRET_KEY>", magic.NewDefaultClient())
userInfo, err := m.User.GetMetadataByToken("<DID_TOKEN>")
...
}

Creating a Token Instance

The Token provides methods to interact with DID Token.

package main
import (
"github.com/magiclabs/magic-admin-go"
"github.com/magiclabs/magic-admin-go/token"
)
func main() {
tk, err := token.NewToken(did)
if err != nil {
return
}
if err := tk.Validate(); err != nil {
return
}
...
}