odin_tokens

package module
v0.0.0-...-8a2c50c Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: ISC Imports: 8 Imported by: 0

README

github.com/4Players/odin-tokens-go

GitHub License

This is a lightweight module to generate API keys and tokens used by 4Players ODIN.

4Players ODIN is a cross-platform software development kit (SDK) that enables developers to integrate voice and video chat technology into multiplayer games.

Flowchart

graph TB
  RandomBytes[Random Bytes] --> AccessKey;
  AccessKey --> PublicKey;
  AccessKey --> SecretKey;
  PublicKey --> KeyId;

Example

import (
    "fmt"
    odin_tokens "github.com/4Players/odin-tokens-go"
)

accessKey := "<YOUR API KEY HERE>"

tokenGenerator, _ := odin_tokens.NewTokenGenerator(accessKey)
token, _ := tokenGenerator.CreateToken("room123", "user123", odin_tokens.TokenOptions{Customer: "exampleCustomer", Lifetime: 300})
fmt.Println("Generated Token:", token)

Terminology

Term Description
AccessKey Gives access to the ODIN network for a customer. It is a 44 character long Base64-String, which consists of a version, random bytes and a checksum.
SecretKey Generated from the AccessKey, it is based on the Ed25519-Curve and used to sign a Token generated by the customer.
PublicKey Generated from the AccessKey, it is based on the Ed25519-Curve and must be uploaded to 4Players so that a generated Token can be verified.
KeyId A shortened PublicKey, included in Token, making it possible to identify what PublicKey must be used to verify the Token.
Token A JWT given to the game clients that allows them to connect to a voice/video chat room in the ODIN network.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateAccessKey

func GenerateAccessKey() (string, error)

GenerateAccessKey generates a new ODIN access key.

func GetKeyId

func GetKeyId(publicKey ed25519.PublicKey) string

GetKeyId generates a key ID from a given public key.

Types

type KeyPair

type KeyPair struct {
	PublicKey ed25519.PublicKey
	SecretKey ed25519.PrivateKey
}

func LoadAccessKey

func LoadAccessKey(accessKey string) (KeyPair, error)

LoadAccessKey validates and loads a key pair from an ODIN access key.

type TokenGenerator

type TokenGenerator struct {
	KeyId     string
	SecretKey ed25519.PrivateKey
}

TokenGenerator generates tokens for ODIN network access.

func NewTokenGenerator

func NewTokenGenerator(credentials interface{}) (*TokenGenerator, error)

NewTokenGenerator creates a TokenGenerator from either an access key or key pair.

func (*TokenGenerator) CreateToken

func (tg *TokenGenerator) CreateToken(roomId string, userId string, options TokenOptions) (string, error)

CreateToken creates a signed JWT token to access the ODIN room.

type TokenOptions

type TokenOptions struct {
	Customer string
	Audience string
	Subject  string
	Lifetime int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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