osindynamodb

package module
v0.0.0-...-365d46d Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2018 License: MIT Imports: 6 Imported by: 0

README

osin-dynamodb

Circle CI GoDoc Coverage Status Report Card

This package implements the storage for OSIN with Amazon DynamoDB using aws-sdk-go.

Installation

Install library with go get github.com/uniplaces/osin-dynamodb

or if you use glide with glide get github.com/uniplaces/osin-dynamodb

Usage

import (
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/dynamodb"
	"github.com/uniplaces/osin-dynamodb"
	"github.com/RangelReale/osin"
	"os"
)

func main() {
    // This is configuration for local DynamoDB instance used in tests,
    // for details how to configure your real AWS DynamoDB connection check DynamoDB documentation
	os.Clearenv()
	os.Setenv("AWS_ACCESS_KEY_ID", "a")
	os.Setenv("AWS_SECRET_ACCESS_KEY", "b")

	svc := dynamodb.New(session.New(&aws.Config{
		Endpoint: aws.String("http://localhost:4567"),
		Region:   aws.String("us-west-1"),
	}))
	
	// You can use CreateStorageConfig helper to create configuration or you can create it by yourself
	storageConfig := osindynamodb.CreateStorageConfig("oauth_table_prefix_")
	
	// Initialization
    store := osindynamodb.New(svc, storageConfig)
    server := osin.NewServer(osin.NewServerConfig(), store)

    // For further details how to use osin server check osin documentation
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClientNotFound is returned by GetClient if client was not found
	ErrClientNotFound = osin.ErrNotFound
	// ErrAuthorizeNotFound is returned by LoadAuthorize if authorization code was not found
	ErrAuthorizeNotFound = osin.ErrNotFound
	// ErrAccessNotFound is returned by LoadAccess if access token was not found
	ErrAccessNotFound = osin.ErrNotFound
	// ErrRefreshNotFound is returned by LoadRefresh if refresh token was not found
	ErrRefreshNotFound = osin.ErrNotFound
	// ErrTokenExpired is returned by LoadAccess, LoadAuthorize or LoadRefresh if token or code expired
	ErrTokenExpired = errors.New("Token expired")
)

Functions

This section is empty.

Types

type Storage

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

Storage implements the storage interface for OSIN (https://github.com/RangelReale/osin) with Amazon DynamoDB (https://aws.amazon.com/dynamodb/) using aws-sdk-go (https://github.com/aws/aws-sdk-go).

func New

func New(db *dynamodb.DynamoDB, config StorageConfig) *Storage

New returns a new DynamoDB storage instance.

func (*Storage) Clone

func (receiver *Storage) Clone() osin.Storage

Clone the storage if needed. Has no effect with this library, it's only to satisfy interface.

func (*Storage) Close

func (receiver *Storage) Close()

Close the resources the Storage potentially holds. Has no effect with this library, it's only to satisfy interface.

func (*Storage) CreateClient

func (receiver *Storage) CreateClient(client osin.Client) error

CreateClient adds new client. This is not a part of interface and as so, it's never used in osin flow. However can be really usefull for applications to add new clients.

func (*Storage) CreateSchema

func (receiver *Storage) CreateSchema() error

CreateSchema initiates db with basic schema layout This is not a part of interface but can be useful for initiating basic schema and for tests

func (*Storage) DropSchema

func (receiver *Storage) DropSchema() error

DropSchema drops all tables This is not a part of interface but can be useful in tests

func (*Storage) GetClient

func (receiver *Storage) GetClient(id string) (osin.Client, error)

GetClient loads the client by id (client_id)

func (*Storage) LoadAccess

func (receiver *Storage) LoadAccess(token string) (accessData *osin.AccessData, err error)

LoadAccess retrieves access data by token. Client information is loaded together. Can return error if expired.

func (*Storage) LoadAuthorize

func (receiver *Storage) LoadAuthorize(code string) (authorizeData *osin.AuthorizeData, err error)

LoadAuthorize looks up AuthorizeData by a code. Client information is loaded together. Can return error if expired.

func (*Storage) LoadRefresh

func (receiver *Storage) LoadRefresh(token string) (accessData *osin.AccessData, err error)

LoadRefresh retrieves refresh AccessData. Client information is loaded together. Refresh token doesn't expire.

func (*Storage) RemoveAccess

func (receiver *Storage) RemoveAccess(token string) error

RemoveAccess revokes or deletes an AccessData.

func (*Storage) RemoveAuthorize

func (receiver *Storage) RemoveAuthorize(code string) error

RemoveAuthorize revokes or deletes the authorization code.

func (*Storage) RemoveClient

func (receiver *Storage) RemoveClient(id string) error

RemoveClient revokes or deletes client. This is not a part of interface and as so, it's never used in osin flow. However can be really usefull for applications to remove or revoke clients.

func (*Storage) RemoveRefresh

func (receiver *Storage) RemoveRefresh(token string) error

RemoveRefresh revokes or deletes refresh AccessData.

func (*Storage) SaveAccess

func (receiver *Storage) SaveAccess(accessData *osin.AccessData) error

SaveAccess writes AccessData.

func (*Storage) SaveAuthorize

func (receiver *Storage) SaveAuthorize(authorizeData *osin.AuthorizeData) error

SaveAuthorize saves authorize data.

func (*Storage) SaveRefresh

func (receiver *Storage) SaveRefresh(accessData *osin.AccessData) error

SaveRefresh writes AccessData for refresh token This method is not a part of interface and as so, it's never used in osin flow. This method is used internally by SaveAccess(accessData *osin.AccessData) and can be useful for testing

type StorageConfig

type StorageConfig struct {
	// ClientTable is the name of table for clients
	ClientTable string
	// AuthorizeTable is the name of table for authorization codes
	AuthorizeTable string
	// AccessTable is the name of table for access tokens
	AccessTable string
	// RefreshTable is the name of table for refresh tokens
	RefreshTable string
	// CreateUserData is a function that allows you to create struct
	// to which osin.AccessData.UserData will be json.Unmarshaled.
	// Example:
	// struct AppUserData{
	// 	Username string
	// }
	// func() interface{} {
	// 	return &AppUserData{}
	// }
	CreateUserData func() interface{}
}

StorageConfig allows to pass configuration to Storage on initialization

func CreateStorageConfig

func CreateStorageConfig(prefix string) StorageConfig

CreateStorageConfig prefixes all table names and returns StorageConfig

type UserData

type UserData interface {
	// ToAttributeValues lists user data as attribute values for DynamoDB table
	ToAttributeValues() map[string]*dynamodb.AttributeValue
}

UserData is an interface that allows you to store UserData values as DynamoDB attributes in AccessTable and RefreshTable

Jump to

Keyboard shortcuts

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