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 ¶
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 ¶
AuthHeader returns the full Authorization header value for a token.
func AuthScheme ¶
AuthScheme returns the HTTP Authorization scheme for the given token. API tokens use "Api-Token"; all others use "Bearer".
func ExtractJWTScopes ¶
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 ¶
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 ¶
IsAPIToken reports whether the token is a Dynatrace API token (dt0c01.* prefix).
func IsPlatformToken ¶
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 )