hcstore

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: MIT Imports: 10 Imported by: 0

README

Hazelcast store for go-oauth2/oauth2

CircleCI codecov

The store requires a runnig *hazelcast.Client to manage tokens and codes.

package main 

import (
    "context"

    "github.com/go-oauth2/oauth2/v4"
    "github.com/go-oauth2/oauth2/v4/models"
    "github.com/hazelcast/hazelcast-go-client"

    "github.com/clowre/go-oauth2-hazelcast"
)

func main() {
    
    ctx := context.Background()
    client, err := hazelcast.StartNewClient(ctx)
    if err != nil {
        panic(err)
    }
    defer client.Shutdown()

    store, err := hcstore.NewTokenStore(
        client,
        hcstore.WithAccessMapName("access_tokens"),
        hcstore.WithRefreshMapName("refresh_tokens"),
        hcstore.WithCodesMapName("codes"),
    )
    if err != nil {
        panic(err)
    }
}

The tests for this package assumes that there is a Hazelcast cluster running on localhost:5701.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTokenStore

func NewTokenStore(client *hazelcast.Client, opts ...TokenStoreOption) (oauth2.TokenStore, error)

NewTokenStore creates an instances of `oauth2.TokenStore` connected to a Hazelcast cluster. This implementation relies on Hazelcast maps to manage access tokens, refresh tokens, and codes. By default, access tokens, refresh toknes, and codes are stored in maps oauth2_access_tokens, oauth2_refresh_tokens, and oauth2_codes respectively, but this can be changed by `WithAccessMapName`, `WithRefreshMapName`, and `WithCodesMapName` options. This package assumes that it will be supplied with a valid Hazelcast client, leaving the connecting/disconnecting to the cluser to its users.

Types

type TokenStoreOption

type TokenStoreOption func(ts *tokenStore) error

TokenStoreOption is a function that can be used to modify behavior of the `tokenStore`.

func WithAccessMapName

func WithAccessMapName(name string) TokenStoreOption

WithAccessMapName sets the name of the map that is used to save access tokens. An error is returned if the name is empty.

func WithCodesMapName

func WithCodesMapName(name string) TokenStoreOption

WithCodesMapName sets the name of the map that is used to save codes. An error is returned if the name is empty.

func WithRefreshMapName

func WithRefreshMapName(name string) TokenStoreOption

WithRefreshMapName sets the name of the map that is used to save refresh tokens. An error is returned if the name is empty.

Jump to

Keyboard shortcuts

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