mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-24 22:26:54 +02:00
Refactor Auth Service Protos, Add Access Rules (#1411)
* Refactor auth/service into two protos * Accounts Proto * Store Prefixes * Misc * Tweak Protos Co-authored-by: Ben Toogood <ben@micro.mu> Co-authored-by: Asim Aslam <asim@aslam.me>
This commit is contained in:
@ -2,6 +2,7 @@ package basic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@ -15,6 +16,11 @@ type Basic struct {
|
||||
store store.Store
|
||||
}
|
||||
|
||||
var (
|
||||
// StorePrefix to isolate tokens
|
||||
StorePrefix = "tokens/"
|
||||
)
|
||||
|
||||
// NewTokenProvider returns an initialized basic provider
|
||||
func NewTokenProvider(opts ...token.Option) token.Provider {
|
||||
options := token.NewOptions(opts...)
|
||||
@ -51,7 +57,7 @@ func (b *Basic) Generate(subject string, opts ...token.GenerateOption) (*auth.To
|
||||
|
||||
// write to the store
|
||||
err = b.store.Write(&store.Record{
|
||||
Key: token.Token,
|
||||
Key: fmt.Sprintf("%v%v", StorePrefix, token.Token),
|
||||
Value: bytes,
|
||||
Expiry: options.Expiry,
|
||||
})
|
||||
@ -66,7 +72,7 @@ func (b *Basic) Generate(subject string, opts ...token.GenerateOption) (*auth.To
|
||||
// Inspect a token
|
||||
func (b *Basic) Inspect(t string) (*auth.Token, error) {
|
||||
// lookup the token in the store
|
||||
recs, err := b.store.Read(t)
|
||||
recs, err := b.store.Read(StorePrefix + t)
|
||||
if err == store.ErrNotFound {
|
||||
return nil, token.ErrInvalidToken
|
||||
} else if err != nil {
|
||||
|
Reference in New Issue
Block a user