service_auth

package
v0.0.0-...-f839e32 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingMetadata      = status.Errorf(codes.InvalidArgument, "No metadata provided")
	ErrMissingAuthorization = status.Errorf(codes.Unauthenticated, "No authorization data or header provided")
	ErrMissingToken         = status.Errorf(codes.Unauthenticated, "No authorization token provided")
	ErrMissingBearer        = status.Errorf(codes.Unauthenticated, "No bearer token provided within authorization token")
	ErrInvalidToken         = status.Errorf(codes.Unauthenticated, "Invalid token")
	ErrInvalidClaims        = status.Errorf(codes.Unauthenticated, "Invalid claims")

	ErrInvalidMapClaims = fmt.Errorf("unable to map claims")
)

Errors

Functions

func AuthorizeGRPC

func AuthorizeGRPC(ctx context.Context) error

AuthorizeGRPC performs gRPC auth

func AuthorizeHTTP

func AuthorizeHTTP(request *http.Request) error

AuthorizeHTTP performs HTTP auth

func GetBearerClaims

func GetBearerClaims(authorizationHeader []string, claims jwt.Claims) (jwt.Claims, error)

GetBearerClaims fetches authorization claims from a request's authorization header NB: `claims` is used as an output value Provided `claims` is filled with values from the token. Thus, `claims` jwt.Claims should be writable-by-value type, such as a pointer to a struct, such as Ex.: &ScopeClaims{} or it can be a map, Ex.: jwt.MapClaims{} because, `claims` is filled with data, fetched from context

func GetBearerMapClaims

func GetBearerMapClaims(authorizationHeader []string) (jwt.MapClaims, error)

GetBearerMapClaims get map claims from 'Bearer XXX' token

func GetMapClaimsGRPC

func GetMapClaimsGRPC(ctx context.Context) (jwt.MapClaims, error)

GetMapClaimsGRPC ensures a valid token exists within a request's metadata and authorizes the token received from Metadata

func GetMapClaimsHTTP

func GetMapClaimsHTTP(request *http.Request) (jwt.MapClaims, error)

GetMapClaimsHTTP ensures a valid token exists within a request's metadata and authorizes the token received from Metadata

func SetupOAuth

func SetupOAuth(config sections.OAuthConfigurator) ([]grpc.ServerOption, error)

SetupOAuth prepares gRPC server options with OAuth from config

func SetupOTP

func SetupOTP(config sections.OAuthConfigurator) ([]grpc.ServerOption, error)

SetupOTP prepares gRPC server options for OTP auth

Types

type ScopeClaims

type ScopeClaims struct {
	jwt.StandardClaims
	// Scope is a synonym to permission(s). Set of space-separated items.
	Scope string `json:"scope"`
}

ScopeClaims define scope token. It is an Access Token, which provides scope (set of permissions) which this token (claim) provides. Scope is a synonym to permission(s), both terms are usable. Token example 1:

{
  aud: "https://atlas-aud",
  exp: 1630351936,
  iat: 1630265536,
  iss: "https://<tenant>.auth0.com/",
  azp: "auth0 ClientID of the application",
  gty: "client-credentials"
  sub: "sub@clients",
  scope: "permission-scope-read",
}

Token example 2:

{
  iss: "https://<tenant>.auth0.com/",
  sub: "auth0|user id goes here 3e65",
  aud: [
    "audience",
    "https://auth0.com/userinfo"
  ],
  iat: 1637762859,
  exp: 1637849259,
  azp: "auth0 ClientID of the application",
  scope: "openid profile email"
}

Where:

	 aud: Audience
	 exp: Expires At
	 jti: Id
	 iat: Issued At
	 iss: Issuer
	 nbf: Not Before
	 sub: Subject
  azp: Authorized Parties (OIDC claims)

func (ScopeClaims) Dump

func (c ScopeClaims) Dump()

Dump logs claims

func (ScopeClaims) Valid

func (c ScopeClaims) Valid() error

Valid checks whether claims are valid.

Jump to

Keyboard shortcuts

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