oauth

package
v0.0.0-...-cda7898 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AuthHeader is the key of the authorization header.
	AuthHeader = "Authorization"

	// AuthHeaderBearer is the prefix for the authorization token in AuthHeader.
	AuthHeaderBearer = "Bearer"

	// AuthUserHeader is the key of the header which indicates whether an action is made on behalf of a user
	AuthUserHeader = "Auth-User"

	// UpdatePermitStatusScope is the scope name required for updating a permit's scope
	UpdatePermitStatusScope = "status"

	// AuthTypeHeader is the key of the service-host header
	AuthTypeHeader = "Auth-Type"

	// DropboxAuthTypeValue is the value of the AuthTypeHeader key for the Dropbox services
	DropboxAuthTypeValue = "Dropbox"

	// CargoAuthTypeValue is the value of the AuthTypeHeader key for the Cargo services
	CargoAuthTypeValue = "Cargo"

	// ServiceAuthCodeTypeValue is the value of service using the authorization code flow for AuthTypeHeader key
	ServiceAuthCodeTypeValue = "Service AuthCode"

	// ContextAppKey is the context key used to get and set the client's appID in the context.
	ContextAppKey = "appID"

	// ContextScopesKey is the context key used to get and set the client's scopes in the context.
	ContextScopesKey = "scopes"

	// ContextAuthType is the context key used to get and set the auth type of the client in the context.
	ContextAuthType = "authType"

	// UploadScope is the scope required for upload
	UploadScope = "upload"

	// GetFileScope is the scope required for getting a file's metadata
	GetFileScope = "get_metadata"

	// ShareScope is the scope required for file share and unshare
	ShareScope = "share"

	// DownloadScope is the scope required for file download
	DownloadScope = "download"

	// DeleteScope is the scope required for file deletion
	DeleteScope = "delete"

	// DriveAppID is the app ID of the drive client.
	DriveAppID = "drive"

	// DropboxAppID is the app ID of the dropbox client.
	DropboxAppID = "dropbox"

	// CargoAppID is the app ID of the cargo client.
	CargoAppID = "cargo"

	// TransactionClientLabel is the label of the custom transaction field : client-name.
	TransactionClientLabel = "client"

	// ConfigTomcalDest is the name of the environment variable containing the tomcal dest name.
	ConfigTomcalDest = "tomcal_dest_value"

	// ConfigCtsDest is the name of the environment variable containing the cts dest name.
	ConfigCtsDest = "cts_dest_value"
)

Variables

This section is empty.

Functions

func SetApmClient

func SetApmClient(ctx *gin.Context, clientID string)

SetApmClient adds a clientID to the current apm transaction.

Types

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware is a structure that handles the authentication middleware.

func NewOAuthMiddleware

func NewOAuthMiddleware(
	spikeConn *grpcPoolTypes.ConnPool,
	userConn *grpcPoolTypes.ConnPool,
	logger *logrus.Logger,
) *Middleware

NewOAuthMiddleware generates a middleware. If logger is non-nil then it will be set as-is, otherwise logger would default to logrus.New().

func (*Middleware) AuthorizationScopeMiddleware

func (m *Middleware) AuthorizationScopeMiddleware(requiredScope string) gin.HandlerFunc

AuthorizationScopeMiddleware creates a middleware function that checks the scopes in context. If the request is not from a service (AuthTypeHeader), Next will be immediately called. If scopes are nil, the client is the drive client which is fine. Else, the required scope should be included in the scopes array. If the required scope exists,and a delegator exists too, the function will set the context user to be the delegator.

func (*Middleware) ValidateRequiredScope

func (m *Middleware) ValidateRequiredScope(ctx *gin.Context, requiredScope string) bool

ValidateRequiredScope checks if there is a specific scope in the context (unless it is the drive client).

Jump to

Keyboard shortcuts

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