identity-go

module
v2.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2021 License: Apache-2.0

README

Tanker logo

Identity SDK

Actions Status codecov GoDoc

Identity generation in Go for the Tanker SDK.

Installation

go get github.com/TankerHQ/identity-go/v2/identity

Usage

The server-side code below demonstrates a typical flow to safely deliver identities to your users:

import (
	"fmt"
	"errors"

	"github.com/TankerHQ/identity-go/v2/identity"
)

var config = identity.Config{
	AppID:     "<app-id>",
	AppSecret: "<app-secret>",
}

// Example server-side function in which you would implement checkAuth(),
// retrieveIdentity() and storeIdentity() to use your own authentication
// and data storage mechanisms:
func getIdentity(userID string) (*string, error) {
	// Always ensure userID is authenticated before returning a identity
	if !isAuthenticated(userID) {
		return nil, errors.New("Unauthorized")
	}

	// Retrieve a previously stored identity for this user
	identity := retrieveIdentity(userID)

	// If not found, create a new identity
	if identity == "" {
		identity, err := identity.Create(config, userID)
		if err != nil {
			return nil, err
		}

		// Store the newly generated identity
		storeIdentity(userID, identity)
	}

	// From now, the same identity will always be returned to a given user
	return &identity, nil
}

func getPublicIdentity(userID string) (*string, error) {
	// Retrieve a previously stored identity for this user
	tkIdentity := retrieveIdentity(userID)
	if tkIdentity == "" {
		return nil, errors.New("Not found")
	}

	publicIdentity, err := identity.GetPublicIdentity(tkIdentity)
	if err != nil {
		return nil, err
	}

	return publicIdentity, nil
}

Read more about identities in the Tanker guide.

Development

Run tests:

go test ./... -test.v

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/TankerHQ/identity-go.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL