oauth2dynamodb

package module
v0.0.0-...-eac733d Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: MIT Imports: 10 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/morage/go-oauth2-dynamodb

Usage (specifying credentials)

package main

import (
	"github.com/aws/aws-sdk-go/aws"
	oauth2dynamodb "github.com/moorage/go-oauth2-dynamodb"
)

func main() {
	manager := manage.NewDefaultManager()
	conf, err := oauth2dynamodb.NewConfig(
		aws.NewConfig(), // however you want to config
		"oauth2_basic", // Oauth2 basic table name
		"oauth2_access", // Oauth2 access table name
		"oauth2_refresh", // Oauth2 refresh table name
	)
	if err != nil {
		...
		return
	}
	manager.MustTokenStorage(
		oauth2dynamodb.NewTokenStore(conf),
	)
	// ...
}

Usage (with IAM Role configured for ec2 or Lambda)

package main

import (
	"github.com/aws/aws-sdk-go/aws"
  oauth2dynamodb "github.com/moorage/go-oauth2-dynamodb"
)

func main() {
	manager := manage.NewDefaultManager()
	conf, err := oauth2dynamodb.NewConfig(
		aws.NewConfig(), // however you want to config
		"oauth2_basic", // Oauth2 basic table name
		"oauth2_access", // Oauth2 access table name
		"oauth2_refresh", // Oauth2 refresh table name
	)
	if err != nil {
		...
		return
	}
	manager.MustTokenStorage(
		dynamo.NewTokenStore(conf),
	)
	// ...
}

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_ID=AKIA******
export AWS_SECRET_ACCESS_KEY=**************
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(tokenStorage *DynamoDbTokenStore, info oauth2.TokenInfo, id string) (err error)

func CreateWithAuthorizationCode

func CreateWithAuthorizationCode(tokenStorage *DynamoDbTokenStore, info oauth2.TokenInfo, id string) (err error)

func CreateWithRefreshToken

func CreateWithRefreshToken(tokenStorage *DynamoDbTokenStore, info oauth2.TokenInfo) (err error)

func NewTokenStore

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

NewTokenStore returns an gopkg.in/oauth2.v3/store compatible wrapper

Types

type Config

type Config struct {
	SESSION *session.Session
	TABLE   *TableConfig
}

Config dynamodb configuration parameters

func NewConfig

func NewConfig(awsConfig *aws.Config, basicTableName string, accessTableName string, refreshTablName string) (*Config, error)

NewConfig create dynamodb configuration

type DynamoDbTokenStore

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

DynamoDbTokenStore is our implementation of oauth2.TokenStore

func (*DynamoDbTokenStore) Create

func (tokenStorage *DynamoDbTokenStore) Create(info oauth2.TokenInfo) (err error)

Create and store the new token information

func (*DynamoDbTokenStore) GetByAccess

func (tokenStorage *DynamoDbTokenStore) GetByAccess(access string) (to oauth2.TokenInfo, err error)

GetByAccess use the access token for token information data

func (*DynamoDbTokenStore) GetByCode

func (tokenStorage *DynamoDbTokenStore) GetByCode(code string) (to oauth2.TokenInfo, err error)

GetByCode use the authorization code for token information data

func (*DynamoDbTokenStore) GetByRefresh

func (tokenStorage *DynamoDbTokenStore) GetByRefresh(refresh string) (to oauth2.TokenInfo, err error)

GetByRefresh use the refresh token for token information data

func (*DynamoDbTokenStore) RemoveByAccess

func (tokenStorage *DynamoDbTokenStore) RemoveByAccess(access string) (err error)

RemoveByAccess use the access token to delete the token information

func (*DynamoDbTokenStore) RemoveByCode

func (tokenStorage *DynamoDbTokenStore) RemoveByCode(code string) (err error)

RemoveByCode use the authorization code to delete the token information

func (*DynamoDbTokenStore) RemoveByRefresh

func (tokenStorage *DynamoDbTokenStore) RemoveByRefresh(refresh string) (err error)

RemoveByRefresh use the refresh token to delete the token information

type TableConfig

type TableConfig struct {
	BasicCname   string
	AccessCName  string
	RefreshCName string
}

TableConfig internally stores the table names to use for dynamodb

Jump to

Keyboard shortcuts

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