ic

package module
v0.0.0-...-9bbaa49 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 22 Imported by: 1

README

ic-go-sdk

This is AccelByte's IC Go SDK for integrating with IC in Go projects.

Usage

Importing package
import "github.com/AccelByte/ic-go-sdk"
Creating default IC client
cfg := &iam.Config{
    BaseURL: "<IAM URL>",
    ClientID: "<client ID>",
    ClientSecret: "<client secret>",
}

client := iam.NewDefaultClient(cfg)

cfg := &ic.Config{
    BaseURL:      "<IAM URL>",
    ClientID:     "<client ID>",
    ClientSecret: "<client secret>",
}
client := ic.NewDefaultClient(cfg)
Validate config
_, err := client.ClientToken()
if err != nil {
	logrus.Fatalf("ic-go-sdk start err: %v \n", err)
}
Example:
  1. replace the placeholder in example/example.go
  2. go build example.go

Documentation

Index

Constants

View Source
const (
	ActionCreate = 1
	ActionRead   = 1 << 1
	ActionUpdate = 1 << 2
	ActionDelete = 1 << 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClaimRole

type ClaimRole struct {
	RoleID         string `json:"roleId"`
	OrganizationID string `json:"organizationId,omitempty" description:"if the role scope is ORG, then organizationId is required"`
	ProjectID      string `json:"projectId,omitempty" description:"if the role scope is PROJ, then projectId is required"`
}

type Client

type Client interface {
	ClientToken() (string, error)

	ValidateAccessToken(accessToken string) (bool, error)

	ValidateAndParseClaims(accessToken string) (*JWTClaims, error)

	// ValidatePermission validates if an access token has right for a specific permission
	// requiredPermission: permission to access resource, example:
	// 		{Resource: "ORG:{organizationId}:USER:{userId}:PROJ:{projectId}", Action: 2}
	// permissionResources: resource string to replace the `{}` placeholder in `requiredPermission`
	ValidatePermission(claims *JWTClaims, requiredPermission Permission,
		permissionResources map[string]string) (bool, error)

	GetRolePermissions(roleID string) (perms []Permission, err error)

	GetClientInformation(clientID string) (*ClientInformation, error)
}

type ClientInformation

type ClientInformation struct {
	ClientName  string `json:"clientName"`
	RedirectURI string `json:"redirectUri"`
	BaseURI     string `json:"baseUri"`
}

type Config

type Config struct {
	BaseURL      string
	ClientID     string
	ClientSecret string
	Debug        bool
}

type DefaultClient

type DefaultClient struct {
	// contains filtered or unexported fields
}

DefaultClient define oauth client config

func NewDefaultClient

func NewDefaultClient(config *Config) *DefaultClient

func (*DefaultClient) ClientToken

func (client *DefaultClient) ClientToken() (string, error)

func (*DefaultClient) ClientTokenGrant

func (client *DefaultClient) ClientTokenGrant(opts ...Option) (token string, ttl *time.Duration, err error)

func (*DefaultClient) GetClientInformation

func (client *DefaultClient) GetClientInformation(clientID string) (*ClientInformation, error)

func (*DefaultClient) GetKeys

func (client *DefaultClient) GetKeys() (keys map[string]*rsa.PublicKey, err error)

func (*DefaultClient) GetRolePermissions

func (client *DefaultClient) GetRolePermissions(roleID string) (perms []Permission, err error)

func (*DefaultClient) ValidateAccessToken

func (client *DefaultClient) ValidateAccessToken(accessToken string) (bool, error)

func (*DefaultClient) ValidateAndParseClaims

func (client *DefaultClient) ValidateAndParseClaims(accessToken string) (*JWTClaims, error)

func (*DefaultClient) ValidatePermission

func (client *DefaultClient) ValidatePermission(claims *JWTClaims, requiredPermission Permission,
	permissionResources map[string]string) (bool, error)

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type JWK

type JWK struct {
	Kty string `json:"kty"`
	Use string `json:"use"`
	Kid string `json:"kid"`
	N   string `json:"n"`
	E   string `json:"e"`
}

JWK contains json web key's data

type JWTClaims

type JWTClaims struct {
	OrganizationID string       `json:"organizationId"`
	DisplayName    string       `json:"display_name"`
	Roles          []ClaimRole  `json:"roles"`
	Scope          string       `json:"scope"`
	ClientID       string       `json:"client_id"`
	Permissions    []Permission `json:"permissions"`
	jwt.Claims
}

JWTClaims holds data stored in a JWT access token with additional Justice Flags field

func (*JWTClaims) Validate

func (c *JWTClaims) Validate() error

Validate checks if the JWT is still valid

type Keys

type Keys struct {
	Keys []JWK `json:"keys"`
}

Keys contains json web keys

type Option

type Option func(*Options)

type Options

type Options struct {
	// contains filtered or unexported fields
}

type Permission

type Permission struct {
	Resource string `json:"resource"`
	Action   int    `json:"action"`
}

type Role

type Role struct {
	RoleID      string       `json:"roleId"`
	Permissions []Permission `json:"permissions"`
}

type TokenResponse

type TokenResponse struct {
	AccessToken  string   `json:"access_token"`
	RefreshToken string   `json:"refresh_token"`
	IDToken      string   `json:"id_token"`
	ExpiresIn    int      `json:"expires_in"`
	TokenType    string   `json:"token_type"`
	Roles        []string `json:"roles"`
	UserID       string   `json:"user_id"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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