go_oauth2_hashed

package module
v0.0.0-...-1257f4e Latest Latest
Warning

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

Go to latest
Published: May 17, 2025 License: MIT Imports: 5 Imported by: 0

README

go-oauth2-hashed

Small wrapper for go oauth2 client stores to keep client secret hashed.

Usage

package main

import (
	"github.com/go-oauth2/oauth2/v4/manage"
	"github.com/go-oauth2/oauth2/v4/models"
	go_oauth2_hashed "github.com/strowk/go-oauth2-hashed"
)

func main() {
	// ... create your store here

	// wrap the store using Bcrypt hashing
	clientStoreWithHash := go_oauth2_hashed.NewClientStoreWithBcrypt(clientStore)

	// store a client with hashed secret
	err := clientStoreWithHash.HashAndCreate(&models.Client{
		ID:     "client_id",
		Secret: "client_secret",
		Domain: "http://localhost:8080",
		Public: true,
		UserID: "user_id",
	}, clientStore.Create) // refer to original Create method
	if err != nil {
		panic(err)
	}

	// Now you can pass clientStoreWithHash to oauth2 library as usual store
	manager := manage.NewDefaultManager()
	manager.MapClientStorage(clientStore)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BcryptHasher

type BcryptHasher struct{}

func (*BcryptHasher) Hash

func (b *BcryptHasher) Hash(password string) (string, error)

func (*BcryptHasher) Verify

func (b *BcryptHasher) Verify(hashedPassword, password string) error

type ClientInfoWithHash

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

func NewClientInfoWithHash

func NewClientInfoWithHash(
	info oauth2.ClientInfo,
	hasher Hasher,
) *ClientInfoWithHash

func (*ClientInfoWithHash) GetDomain

func (v *ClientInfoWithHash) GetDomain() string

func (*ClientInfoWithHash) GetID

func (v *ClientInfoWithHash) GetID() string

func (*ClientInfoWithHash) GetSecret

func (v *ClientInfoWithHash) GetSecret() string

func (*ClientInfoWithHash) GetUserID

func (v *ClientInfoWithHash) GetUserID() string

func (*ClientInfoWithHash) IsPublic

func (v *ClientInfoWithHash) IsPublic() bool

func (*ClientInfoWithHash) VerifyPassword

func (v *ClientInfoWithHash) VerifyPassword(pass string) bool

type ClientStoreWithHash

type ClientStoreWithHash struct {
	oauth2.ClientStore
	// contains filtered or unexported fields
}

func NewClientStoreWithBcrypt

func NewClientStoreWithBcrypt(store oauth2.ClientStore) *ClientStoreWithHash

func NewClientStoreWithHash

func NewClientStoreWithHash(store oauth2.ClientStore, hasher Hasher) *ClientStoreWithHash

func (*ClientStoreWithHash) GetByID

func (w *ClientStoreWithHash) GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error)

func (*ClientStoreWithHash) HashAndCreate

func (w *ClientStoreWithHash) HashAndCreate(
	info oauth2.ClientInfo,
	createFunc func(oauth2.ClientInfo) error,
) error

type Hasher

type Hasher interface {
	Hash(password string) (string, error)
	Verify(hashedPassword, password string) error
}

Jump to

Keyboard shortcuts

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