auth

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 4 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth provides Dynatrace token type detection and classification.

It distinguishes between API tokens (dt0c01.* prefix), platform tokens (dt0s16.* prefix), and OAuth/JWT bearer tokens, enabling callers to set the correct Authorization header scheme.

Index

Constants

View Source
const (
	// APITokenPrefix is the prefix for Dynatrace API tokens.
	APITokenPrefix = "dt0c01."
	// PlatformTokenPrefix is the prefix for Dynatrace platform tokens.
	PlatformTokenPrefix = "dt0s16."
)

Variables

This section is empty.

Functions

func AuthHeader

func AuthHeader(token string) string

AuthHeader returns the full Authorization header value for a token.

func AuthScheme

func AuthScheme(token string) string

AuthScheme returns the HTTP Authorization scheme for the given token. API tokens use "Api-Token"; all others use "Bearer".

func ExtractJWTScopes

func ExtractJWTScopes(token string) []string

ExtractJWTScopes extracts the granted scopes from a JWT access token. It reads the "scope" claim (a space-delimited string) or, failing that, the "scp" claim (either a space-delimited string or an array of strings). It returns nil when the token is not a decodable JWT, is a Dynatrace platform token (dt0s16.*, not a JWT), or carries no recognizable scope claim. Callers use this as a best-effort fallback for displaying scopes when the scope string was dropped from compact keyring storage.

func ExtractJWTSubject

func ExtractJWTSubject(token string) (string, error)

ExtractJWTSubject extracts the "sub" claim from a JWT token's payload. Returns an error if the token is not a valid JWT or has no "sub" claim. Platform tokens (dt0s16.*) are rejected since they are not JWTs.

func IsAPIToken

func IsAPIToken(token string) bool

IsAPIToken reports whether the token is a Dynatrace API token (dt0c01.* prefix).

func IsPlatformToken

func IsPlatformToken(token string) bool

IsPlatformToken reports whether the token is a Dynatrace platform token (dt0s16.* prefix).

Types

type TokenType

type TokenType int

TokenType represents the classification of a Dynatrace token.

const (
	// TokenTypeBearer is an OAuth or JWT token, sent as "Bearer <token>".
	TokenTypeBearer TokenType = iota
	// TokenTypeAPIToken is a Dynatrace API token (dt0c01.* prefix), sent as "Api-Token <token>".
	TokenTypeAPIToken
	// TokenTypePlatform is a Dynatrace platform token (dt0s16.* prefix), sent as "Bearer <token>".
	TokenTypePlatform
)

func Classify

func Classify(token string) TokenType

Classify determines the type of a Dynatrace token based on its prefix.

Jump to

Keyboard shortcuts

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