func (a *Auth) Inspect(ctx context.Context, req *pb.InspectRequest, rsp *pb.InspectResponse) error {
	acc, err := a.TokenProvider.Inspect(req.Token)
	if err == token.ErrInvalidToken || err == token.ErrNotFound {
		return errors.BadRequest("auth.Auth.Inspect", err.Error())
	} else if err != nil {
		return errors.InternalServerError("auth.Auth.Inspect", "Unable to inspect token: %v", err)
	}
	rsp.Account = serializeAccount(acc)
	return nil
}
Inspect a token and retrieve the account
package handler
import (
	"context"
	"encoding/json"
	"strings"
	"sync"
	"time"
	"github.com/google/uuid"
	pb "github.com/micro/micro/v3/proto/auth"
	"github.com/micro/micro/v3/service/auth"
	"github.com/micro/micro/v3/service/errors"
	"github.com/micro/micro/v3/service/logger"
	"github.com/micro/micro/v3/service/store"
	authns "github.com/micro/micro/v3/util/auth/namespace"
	"github.com/micro/micro/v3/util/auth/token"
	"github.com/micro/micro/v3/util/auth/token/basic"
	"github.com/micro/micro/v3/util/namespace"
	"golang.org/x/crypto/bcrypt"
)
const (
	storePrefixAccounts      = "account"
	storePrefixRefreshTokens = "refresh"
	storePrefixAccountsByName = "accountByName"
)
var defaultAccount = auth.Account{
	ID:     "admin",
	Type:   "user",
	Scopes: []string{"admin"},
	Secret: "micro",
}
type Auth struct {
	Options       auth.Options
	TokenProvider token.Provider
	namespaces map[string]bool
	sync.Mutex
	DisableAdmin bool
}
func (a *Auth) Init(opts ...auth.Option) {
	for _, o := range opts {
		o(&a.Options)
	}
	if a.TokenProvider == nil {
		a.TokenProvider = basic.NewTokenProvider(token.WithStore(store.DefaultStore))
	}
}
func (a *Auth) setupDefaultAccount(ns string) error {
	if ns != namespace.DefaultNamespace {
		return nil
	}
	if a.DisableAdmin {
		return nil
	}
	a.Lock()
	defer a.Unlock()
	if a.namespaces == nil {
		a.namespaces = make(map[string]bool)
	}
	if _, ok := a.namespaces[ns]; ok {
		return nil
	}
	prefix := strings.Join([]string{storePrefixAccounts, ns, ""}, joinKey)
	recs, err := store.Read(prefix, store.ReadPrefix())
	if err != nil {
		return err
	}
	hasUser := false
	for _, rec := range recs {
		acc := &auth.Account{}
		err := json.Unmarshal(rec.Value, acc)
		if err != nil {
			return err
		}
		if acc.Type == "user" {
			hasUser = true
			break
		}
	}
	if !hasUser {
		acc := defaultAccount
		acc.Issuer = ns
		if err := a.createAccount(&acc); err != nil {
			return err
		}
	}
	a.namespaces[ns] = true
	return nil
}
func (a *Auth) Generate(ctx context.Context, req *pb.GenerateRequest, rsp *pb.GenerateResponse) error {
	if len(req.Id) == 0 {
		return errors.BadRequest("auth.Auth.Generate", "ID required")
	}
	if len(req.Type) == 0 {
		req.Type = "user"
	}
	if len(req.Secret) == 0 {
		req.Secret = uuid.New().String()
	}
	if req.Options == nil {
		req.Options = &pb.Options{}
	}
	if len(req.Options.Namespace) == 0 {
		req.Options.Namespace = namespace.FromContext(ctx)
	}
	if err := authns.AuthorizeAdmin(ctx, req.Options.Namespace, "auth.Auth.Generate"); err != nil {
		return err
	}
	key := strings.Join([]string{storePrefixAccounts, req.Options.Namespace, req.Id}, joinKey)
	if _, err := store.Read(key); err != store.ErrNotFound {
		return errors.BadRequest("auth", "Account with this ID already exists")
	}
	acc := &auth.Account{
		ID:       req.Id,
		Type:     req.Type,
		Scopes:   req.Scopes,
		Metadata: req.Metadata,
		Issuer:   req.Options.Namespace,
		Secret:   req.Secret,
		Name:     req.Name,
	}
	if err := a.createAccount(acc); err != nil {
		return err
	}
	rsp.Account = serializeAccount(acc)
	rsp.Account.Secret = req.Secret  
	return nil
}
func (a *Auth) createAccount(acc *auth.Account) error {
	key := strings.Join([]string{storePrefixAccounts, acc.Issuer, acc.ID}, joinKey)
	if _, err := store.Read(key); err != store.ErrNotFound {
		return errors.BadRequest("auth.Auth.Generate", "Account with this ID already exists")
	}
	if acc.Metadata == nil {
		acc.Metadata = map[string]string{}
	}
	if acc.Name == "" {
		acc.Name = acc.ID
	}
	usernameKey := strings.Join([]string{storePrefixAccountsByName, acc.Issuer, acc.Name}, joinKey)
	if _, err := store.Read(usernameKey); err != store.ErrNotFound {
		return errors.BadRequest("auth.Auth.Generate", "Account with this Name already exists")
	}
	secret, err := hashSecret(acc.Secret)
	if err != nil {
		return errors.InternalServerError("auth.Auth.Generate", "Unable to hash password: %v", err)
	}
	acc.Secret = secret
	bytes, err := json.Marshal(acc)
	if err != nil {
		return errors.InternalServerError("auth.Auth.Generate", "Unable to marshal json: %v", err)
	}
	if err := store.Write(&store.Record{Key: key, Value: bytes}); err != nil {
		return errors.InternalServerError("auth.Auth.Generate", "Unable to write account to store: %v", err)
	}
	if err := store.Write(&store.Record{Key: usernameKey, Value: bytes}); err != nil {
		return errors.InternalServerError("auth.Auth.Generate", "Unable to write account to store: %v", err)
	}
	if err := a.setRefreshToken(acc.Issuer, acc.ID, uuid.New().String()); err != nil {
		return errors.InternalServerError("auth.Auth.Generate", "Unable to set a refresh token: %v", err)
	}
	return nil
}