package
0.16.1
Repository: https://github.com/ssh2go/atlas-app-toolkit.git
Documentation: pkg.go.dev

# README

Auth

GetAccountID

We offer a convenient way to extract the AccountID field from an incoming authorization token. For this purpose auth.GetAccountID(ctx, nil) function can be used:

func (s *contactsServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) {
	input := req.GetContact()

	accountID, err := auth.GetAccountID(ctx, nil)
	if err == nil {
		input.AccountId = accountID
	} else if input.GetAccountId() == "" {
		return nil, err
	}

	c, err := DefaultReadContact(ctx, input, s.db)
	if err != nil {
		return nil, err
	}
	return &ReadResponse{Contact: c}, nil
}

When bootstrapping a gRPC server, add middleware that will extract the account_id token from the request context and set it in the request struct. The middleware will have to navigate the request struct via reflection, in the case that the account_id field is nested within the request (like if it's in a request wrapper as per our example above)

# Functions

GetAccountID gets the JWT from a context and returns the AccountID field.
GetJWTField gets the JWT from a context and returns the specified field using the DefaultTokenName.
GetJWTFieldWithTokenType gets the JWT from a context and returns the specified field.
LogrusUnaryServerInterceptor returns grpc.UnaryServerInterceptor which populates request-scoped logrus logger with account_id field.

# Constants

DefaultTokenType is the name of the authorization token (e.g.
MultiTenancyField the field name for a specific tenant.