https://github.com/tankerhq/identity-go
Identity generation in Go for the Tanker SDK
https://github.com/tankerhq/identity-go
Last synced: 2 months ago
JSON representation
Identity generation in Go for the Tanker SDK
- Host: GitHub
- URL: https://github.com/tankerhq/identity-go
- Owner: TankerHQ
- License: other
- Created: 2019-03-12T14:04:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-21T17:28:12.000Z (5 months ago)
- Last Synced: 2025-01-21T18:30:48.738Z (5 months ago)
- Language: Go
- Homepage:
- Size: 181 KB
- Stars: 1
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://opensource.org/licenses/Apache-2.0)
[](https://github.com/TankerHQ/identity-go/actions)
[](https://codecov.io/gh/TankerHQ/identity-go)
[![GoDoc][doc-badge]][doc]# Identity SDK
Identity generation in Go for the [Tanker SDK](https://docs.tanker.io/latest/).
## Installation
```bash
go get github.com/TankerHQ/identity-go/v3
```## Usage
The server-side code below demonstrates a typical flow to safely deliver identities to your users:
```go
import (
"fmt"
"errors""github.com/TankerHQ/identity-go/v3"
)var config = identity.Config{
AppID: "",
AppSecret: "",
}// 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](https://docs.tanker.io/latest/guides/identity-management/).
## Development
Run tests:
```bash
go test ./... -test.v
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/TankerHQ/identity-go.
[build-badge]: https://travis-ci.org/TankerHQ/identity-go.svg?branch=master
[build]: https://travis-ci.org/TankerHQ/identity-go
[doc-badge]: https://godoc.org/github.com/TankerHQ/identity-go/identity?status.svg
[doc]: https://godoc.org/github.com/TankerHQ/identity-go/identity