auth

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package auth provides Azure authentication token acquisition and caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectScope

func DetectScope(urlString string) (string, error)

DetectScope analyzes a URL and returns the appropriate Azure OAuth scope. Returns empty string when the hostname does not match a known Azure service.

func GetAzureToken

func GetAzureToken(ctx context.Context, scope string) (string, error)

GetAzureToken acquires a bearer token for the supplied scope using the shared provider instance (cached credential and token reuse).

func IsAzureHost

func IsAzureHost(urlString string) bool

IsAzureHost checks if a hostname appears to be an Azure service

Types

type AzureTokenProvider

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

AzureTokenProvider implements TokenProvider using azd-core's credential chain (DefaultAzureCredential-equivalent) with in-memory token reuse.

func NewAzureTokenProvider

func NewAzureTokenProvider() (*AzureTokenProvider, error)

NewAzureTokenProvider creates a provider backed by DefaultAzureCredential. The provider caches tokens per scope until close to expiration.

func (*AzureTokenProvider) GetToken

func (p *AzureTokenProvider) GetToken(ctx context.Context, scope string) (string, error)

GetToken retrieves an access token for the specified scope with caching.

type MockTokenProvider

type MockTokenProvider struct {
	Token string
	Error error
}

MockTokenProvider is a mock implementation for testing

func (*MockTokenProvider) GetToken

func (m *MockTokenProvider) GetToken(ctx context.Context, scope string) (string, error)

GetToken returns the mock token or error

type TokenProvider

type TokenProvider interface {
	GetToken(ctx context.Context, scope string) (string, error)
}

TokenProvider supplies OAuth bearer tokens for a given scope.

Jump to

Keyboard shortcuts

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