token_auth

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const DefaultApiTokenHeaderName = "api_token"

DefaultApiTokenHeaderName used if apiTokenHeaderName is empty string

Variables

This section is empty.

Functions

func ClientTokenAuth

func ClientTokenAuth(apiToken string, apiTokenHeaderName string) grpc.UnaryClientInterceptor

ClientTokenAuth provides token header for authentication

Example

Example client with token auth

conn, err := grpc.Dial(
	"localhost:50002",
	grpc.WithBlock(),
	grpc.WithInsecure(),
	grpc.WithUnaryInterceptor(ClientTokenAuth(
		"secret_token",
		"<header name or empty for default>",
	)),
)
if err != nil {
	log.Fatalf("dial failed: %s", err.Error())
}
defer conn.Close()
// ...
Output:

func ServerTokenAuth

func ServerTokenAuth(apiToken string, apiTokenHeaderName string) grpc.UnaryServerInterceptor

ServerTokenAuth provides token header for authentication

Example

Example server with token auth

grpcServer := grpc.NewServer(
	grpc.ChainUnaryInterceptor(
		ServerTokenAuth(
			"secret_token",
			"<header name or empty for default>",
		),
	),
)
fmt.Println(grpcServer)
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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