dynamodb

package module
v0.0.0-...-5e9c5be Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 12 Imported by: 0

README

go-oauth2-dynamodb

DynamoDB store implementation for https://github.com/go-oauth2/oauth2

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

Based on https://github.com/contamobi/go-oauth2-dynamodb

Install

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

Usage

package main

import (
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/dynamodb"
	
	ddbstore "github.com/rjewing/go-oauth2-dynamodb"
	"gopkg.in/oauth2.v3/manage"
)

func main() {
	manager := manage.NewDefaultManager()

	config := &aws.Config{
		Region:   aws.String("us-west-2"),
		Endpoint: aws.String("http://localhost:8000"),
	}
	sess := session.Must(session.NewSession(config))
	client := dynamodb.New(sess)

	// use dynamodb token store
	manager.MapTokenStorage(
	ddbstore.NewTokenStore(client, ddbstore.NewDefaultTokenConfig()),
	)
	// ...
}

Testing

$ docker pull amazon/dynamodb-local
$ docker run -p 8000:8000 amazon/dynamodb-local

This sets up a local dynamodb server running on http://localhost:8000.

MIT License

Copyright (c) 2020 Ryan Ewing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InsertAccessToken

func InsertAccessToken(ts *TokenStore, token string, basicID string, expiresAt string) (err error)

InsertAccessToken inserts an access code into the basic table

func InsertAuthorizationCode

func InsertAuthorizationCode(ts *TokenStore, code string, data []byte, expiresAt string) (err error)

InsertAuthorizationCode inserts an authorization code into the basic table

func InsertRefreshToken

func InsertRefreshToken(ts *TokenStore, token string, basicID string, expiresAt string) (err error)

InsertRefreshToken inserts an access code into the basic table

Types

type ClientConfig

type ClientConfig struct {
	// store clients data collection name(The default is oauth2_clients)
	ClientsCName string
}

ClientConfig client configuration parameters

func NewDefaultClientConfig

func NewDefaultClientConfig() *ClientConfig

NewDefaultClientConfig create a default client configuration

type ClientStore

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

ClientStore DynamoDB storage for OAuth 2.0

func NewClientStore

func NewClientStore(client *dynamodb.DynamoDB, ccfg *ClientConfig) (store *ClientStore)

NewClientStore create a client store instance based on dynamodb

func (*ClientStore) GetByID

func (cs *ClientStore) GetByID(id string) (info oauth2.ClientInfo, err error)

GetByID according to the ID for the client information

func (*ClientStore) RemoveByID

func (cs *ClientStore) RemoveByID(id string) (err error)

RemoveByID use the client id to delete the client information

func (*ClientStore) Set

func (cs *ClientStore) Set(info oauth2.ClientInfo) (err error)

Set set client information

type TokenConfig

type TokenConfig struct {
	// store token based data collection name(The default is oauth2_basic)
	BasicCName string
	// store access token data collection name(The default is oauth2_access)
	AccessCName string
	// store refresh token data collection name(The default is oauth2_refresh)
	RefreshCName string
}

TokenConfig token configuration parameters

func NewDefaultTokenConfig

func NewDefaultTokenConfig() (config *TokenConfig)

NewDefaultTokenConfig returns a default token config

type TokenStore

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

TokenStore stores the dynamodb client and token config

func NewTokenStore

func NewTokenStore(client *dynamodb.DynamoDB, tokenConfig *TokenConfig) (store *TokenStore)

NewTokenStore returns a new token store

func (*TokenStore) Create

func (ts *TokenStore) Create(info oauth2.TokenInfo) (err error)

Create creates

func (*TokenStore) GetByAccess

func (ts *TokenStore) GetByAccess(access string) (ti oauth2.TokenInfo, err error)

GetByAccess use the access token for token information data

func (*TokenStore) GetByCode

func (ts *TokenStore) GetByCode(code string) (ti oauth2.TokenInfo, err error)

GetByCode use the authorization code for token information data

func (*TokenStore) GetByRefresh

func (ts *TokenStore) GetByRefresh(refresh string) (ti oauth2.TokenInfo, err error)

GetByRefresh use the refresh token for token information data

func (*TokenStore) RemoveByAccess

func (ts *TokenStore) RemoveByAccess(access string) (err error)

RemoveByAccess use the access token to delete the token information

func (*TokenStore) RemoveByCode

func (ts *TokenStore) RemoveByCode(code string) (err error)

RemoveByCode use the authorization code to delete the token information

func (*TokenStore) RemoveByRefresh

func (ts *TokenStore) RemoveByRefresh(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