dynamo

package module
v0.0.0-...-956db6c Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 12 Imported by: 0

README

DynamoDB Storage for OAuth 2.0

Based on the https://github.com/go-oauth2/mongo

License

Install

$ go get -u github.com/aubelsb2/go-oauth2-dynamodb

Usage (specifying credentials)

package main

import (
	"github.com/aubelsb2/go-oauth2-dynamodb"
	"gopkg.in/oauth2.v4/manage"
)

func main() {
	manager := manage.NewDefaultManager()
	manager.MustTokenStorage(
		dynamo.NewTokenStore(dynamo.NewTokenStoreConfig(
			"us-east-1", // AWS Region
			"http://localhost:8000", // AWS DynamoDB Endpoint
			"AKIA*********", // AWS Access Key
			"*************", // AWS Secret
                        "oauth2_basic", // Oauth2 basic table name
			"oauth2_access", // Oauth2 access table name
			"oauth2_refresh", // Oauth2 refresh table name
		)),
	)
	// ...
}

Usage (with IAM Role configured for ec2 or Lambda)

package main

import (
	"github.com/aubelsb2/go-oauth2-dynamodb"
	"gopkg.in/oauth2.v4/manage"
)

func main() {
	manager := manage.NewDefaultManager()
	manager.MustTokenStorage(
		dynamo.NewTokenStore(dynamo.NewTokenStoreConfig(
			"us-east-1", // AWS Region
			"", // Emtpy
			"", // Emtpy
			"", // Emtpy
			"oauth2_basic", // Oauth2 basic table name
                        "oauth2_access", // Oauth2 access table name
                        "oauth2_refresh", // Oauth2 refresh table name

		)),
	)
	// ...
}

Client ID version

package main

import (
	"github.com/aubelsb2/go-oauth2-dynamodb"
	"gopkg.in/oauth2.v4/manage"
)

func main() {
	manager := manage.NewDefaultManager()
	manager.MapClientStorage(
		dynamo.NewClientStore(dynamo.NewClientStoreConfig(
			"us-east-1", // AWS Region
			"", // Emtpy
			"", // Emtpy
			"", // Emtpy
			"client_id", // Client id table name

		)),
	)
	// ...
}

Run tests

Start dynamodb local
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb 
Export env variables
export AWS_REGION=us-east-1
export DYNAMODB_ENDPOINT='http://localhost:8000'
export AWS_ACCESS_KEY=AKIA******
export AWS_SECRET=**************
Run tests
go test

MIT License

Copyright (c) 2018 Conta.MOBI

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateWithAccessToken

func CreateWithAccessToken(ctx context.Context, tokenStorage *TokenStore, info oauth2.TokenInfo, id string) (err error)

func CreateWithAuthorizationCode

func CreateWithAuthorizationCode(ctx context.Context, tokenStorage *TokenStore, info oauth2.TokenInfo, id string) (err error)

func CreateWithRefreshToken

func CreateWithRefreshToken(ctx context.Context, tokenStorage *TokenStore, info oauth2.TokenInfo) (err error)

func NewClientStore

func NewClientStore(config *Config) (store oauth2.ClientStore)

func NewTokenStore

func NewTokenStore(config *Config) (store oauth2.TokenStore)

Types

type ClientData

type ClientData struct {
	ID     string
	UserID string
	Domain string
	Secret string
}

func (ClientData) GetDomain

func (cd ClientData) GetDomain() string

func (ClientData) GetID

func (cd ClientData) GetID() string

func (ClientData) GetSecret

func (cd ClientData) GetSecret() string

func (ClientData) GetUserID

func (cd ClientData) GetUserID() string

func (*ClientData) SetDomain

func (cd *ClientData) SetDomain(v string)

func (*ClientData) SetID

func (cd *ClientData) SetID(v string)

func (*ClientData) SetSecret

func (cd *ClientData) SetSecret(v string)

func (*ClientData) SetUserID

func (cd *ClientData) SetUserID(v string)

type ClientStore

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

func (*ClientStore) GetByID

func (cs *ClientStore) GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error)

func (*ClientStore) Set

func (cs *ClientStore) Set(ctx context.Context, cli oauth2.ClientInfo) (err error)

type Config

type Config struct {
	SESSION     *session.Session
	TokenTable  *TableTokenStoreConfig
	ClientTable *TableClientStoreConfig
	ENDPOINT    string
}

Config dynamodb configuration parameters

func NewClientStoreConfig

func NewClientStoreConfig(region string, endpoint string, access_key string, secret string, client_table_name string) (config *Config, err error)

NewClientStoreConfig create dynamodb configuration

func NewConfig

func NewConfig(region string, endpoint string, access_key string, secret string, basic_table_name string, access_table_name string, refresh_table_name string, client_table_name string) (config *Config, err error)

NewConfig create dynamodb configuration

func NewTokenStoreConfig

func NewTokenStoreConfig(region string, endpoint string, access_key string, secret string, basic_table_name string, access_table_name string, refresh_table_name string) (config *Config, err error)

NewTokenStoreConfig create dynamodb configuration

type TableClientStoreConfig

type TableClientStoreConfig struct {
	ClientCname string
}

type TableTokenStoreConfig

type TableTokenStoreConfig struct {
	BasicCname   string
	AccessCName  string
	RefreshCName string
}

type TokenStore

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

func (*TokenStore) Create

func (tokenStorage *TokenStore) Create(ctx context.Context, info oauth2.TokenInfo) (err error)

Create and store the new token information

func (*TokenStore) GetByAccess

func (tokenStorage *TokenStore) GetByAccess(ctx context.Context, access string) (to oauth2.TokenInfo, err error)

GetByAccess use the access token for token information data

func (*TokenStore) GetByCode

func (tokenStorage *TokenStore) GetByCode(ctx context.Context, code string) (to oauth2.TokenInfo, err error)

GetByCode use the authorization code for token information data

func (*TokenStore) GetByRefresh

func (tokenStorage *TokenStore) GetByRefresh(ctx context.Context, refresh string) (to oauth2.TokenInfo, err error)

GetByRefresh use the refresh token for token information data

func (*TokenStore) RemoveByAccess

func (tokenStorage *TokenStore) RemoveByAccess(ctx context.Context, access string) (err error)

RemoveByAccess use the access token to delete the token information

func (*TokenStore) RemoveByCode

func (tokenStorage *TokenStore) RemoveByCode(ctx context.Context, code string) (err error)

RemoveByCode use the authorization code to delete the token information

func (*TokenStore) RemoveByRefresh

func (tokenStorage *TokenStore) RemoveByRefresh(ctx context.Context, refresh string) (err error)

RemoveByRefresh use the refresh token to delete the token information

Jump to

Keyboard shortcuts

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