grpcoauth

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 10 Imported by: 0

README

Hyperscale gRPC OAuth Last release Documentation

Go Report Card

Branch Status Coverage
master Build Status Coveralls

The Hyperscale grpcoauth library provides a simple gRPC credentials.PerRPCCredentials with OAuth

Example

package main

import (
    "github.com/hyperscale-stack/grpcoauth"
)

func main() {
    cert := ...

    authF := func(ctx context.Context, creds *OAuthCredentials) (context.Context, error) {
		// implements your business logic for authenticate
        // creds contains AccessToken or ClientID and ClientSecret

		return ctx, nil
	}

    opts := []grpc.ServerOption{
		grpc.Creds(credentials.NewServerTLSFromCert(&cert)),
		grpc.UnaryInterceptor(UnaryServerInterceptor(authF)),
	}

	gsrv := grpc.NewServer(opts...)


    // init gRPC Dial and init service
    greeter := ...

    _, err = greeter.SayHello(ctx, &greeterv1.SayHelloRequest{}, grpcoauth.PerRPCTokenCredentials("feadbb35-c2be-4529-b2a6-19109e07eaa3"))
}

License

Hyperscale grpcoauth is licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PerRPCClientIDCredentials

func PerRPCClientIDCredentials(clientID string, secret string) grpc.CallOption

PerRPCClientIDCredentials returns a CallOption that sets credentials.PerRPCCredentials with OAuth2 client_id and secret for a call.

func PerRPCTokenCredentials

func PerRPCTokenCredentials(token string) grpc.CallOption

PerRPCTokenCredentials returns a CallOption that sets credentials.PerRPCCredentials with OAuth2 token for a call.

func StreamServerInterceptor

func StreamServerInterceptor(f AuthFunc) grpc.StreamServerInterceptor

func UnaryServerInterceptor

func UnaryServerInterceptor(f AuthFunc) grpc.UnaryServerInterceptor

func WithPerRPCClientIDCredentials

func WithPerRPCClientIDCredentials(clientID string, secret string) grpc.DialOption

WithPerRPCClientIDCredentials returns a DialOption which sets OAuth2 client_id and secret credentials and places auth state on each outbound RPC.

func WithPerRPCTokenCredentials

func WithPerRPCTokenCredentials(token string) grpc.DialOption

WithPerRPCTokenCredentials returns a DialOption which sets OAuth2 token credentials and places auth state on each outbound RPC.

Types

type AuthFunc

type AuthFunc func(ctx context.Context, creds *OAuthCredentials) (context.Context, error)

type OAuthCredentials

type OAuthCredentials struct {
	AccessToken  string
	ClientID     string
	ClientSecret string
}

Jump to

Keyboard shortcuts

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