base

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package base contains a "Base" client that is used by the external public.Client and confidential.Client. Base holds shared attributes that must be available to both clients and methods that act as shared calls.

Index

Constants

View Source
const (
	// AuthorityPublicCloud is the default AAD authority host
	AuthorityPublicCloud = "https://login.microsoftonline.com/common"
)

Variables

View Source
var Now = time.Now

This function wraps time.Now() and is used for refreshing the application was created to test the function against refreshin

Functions

This section is empty.

Types

type AcquireTokenAuthCodeParameters

type AcquireTokenAuthCodeParameters struct {
	Scopes      []string
	Code        string
	Challenge   string
	Claims      string
	RedirectURI string
	AppType     accesstokens.AppType
	Credential  *accesstokens.Credential
	TenantID    string
}

AcquireTokenAuthCodeParameters contains the parameters required to acquire an access token using the auth code flow. To use PKCE, set the CodeChallengeParameter. Code challenges are used to secure authorization code grants; for more information, visit https://tools.ietf.org/html/rfc7636.

type AcquireTokenOnBehalfOfParameters added in v0.4.0

type AcquireTokenOnBehalfOfParameters struct {
	Scopes        []string
	Claims        string
	Credential    *accesstokens.Credential
	TenantID      string
	UserAssertion string
}

type AcquireTokenSilentParameters

type AcquireTokenSilentParameters struct {
	Scopes              []string
	Account             shared.Account
	RequestType         accesstokens.AppType
	Credential          *accesstokens.Credential
	IsAppCache          bool
	TenantID            string
	UserAssertion       string
	AuthorizationType   authority.AuthorizeType
	Claims              string
	AuthnScheme         authority.AuthenticationScheme
	ExtraBodyParameters map[string]string
	CacheKeyComponents  map[string]string
}

AcquireTokenSilentParameters contains the parameters to acquire a token silently (from cache).

type AuthResult

type AuthResult struct {
	Account        shared.Account
	IDToken        accesstokens.IDToken
	AccessToken    string
	ExpiresOn      time.Time
	GrantedScopes  []string
	DeclinedScopes []string
	Metadata       AuthResultMetadata
}

AuthResult contains the results of one token acquisition operation in PublicClientApplication or ConfidentialClientApplication. For details see https://aka.ms/msal-net-authenticationresult

func AuthResultFromStorage

func AuthResultFromStorage(storageTokenResponse storage.TokenResponse) (AuthResult, error)

AuthResultFromStorage creates an AuthResult from a storage token response (which is generated from the cache).

func NewAuthResult

func NewAuthResult(tokenResponse accesstokens.TokenResponse, account shared.Account) (AuthResult, error)

NewAuthResult creates an AuthResult.

type AuthResultMetadata added in v1.2.3

type AuthResultMetadata struct {
	RefreshOn   time.Time
	TokenSource TokenSource
}

AuthResultMetadata which contains meta data for the AuthResult

type Client

type Client struct {
	Token *oauth.Client

	AuthParams authority.AuthParams // DO NOT EVER MAKE THIS A POINTER! See "Note" in New().
	// contains filtered or unexported fields
}

Client is a base client that provides access to common methods and primatives that can be used by multiple clients.

func New

func New(clientID string, authorityURI string, token *oauth.Client, options ...Option) (Client, error)

New is the constructor for Base.

func (Client) Account

func (b Client) Account(ctx context.Context, homeAccountID string) (shared.Account, error)

func (Client) AcquireTokenByAuthCode

func (b Client) AcquireTokenByAuthCode(ctx context.Context, authCodeParams AcquireTokenAuthCodeParameters) (AuthResult, error)

func (Client) AcquireTokenOnBehalfOf added in v0.4.0

func (b Client) AcquireTokenOnBehalfOf(ctx context.Context, onBehalfOfParams AcquireTokenOnBehalfOfParameters) (AuthResult, error)

AcquireTokenOnBehalfOf acquires a security token for an app using middle tier apps access token.

func (Client) AcquireTokenSilent

func (b Client) AcquireTokenSilent(ctx context.Context, silent AcquireTokenSilentParameters) (AuthResult, error)

func (Client) AllAccounts

func (b Client) AllAccounts(ctx context.Context) ([]shared.Account, error)

func (Client) AuthCodeURL

func (b Client) AuthCodeURL(ctx context.Context, clientID, redirectURI string, scopes []string, authParams authority.AuthParams) (string, error)

AuthCodeURL creates a URL used to acquire an authorization code.

func (Client) AuthResultFromToken

func (b Client) AuthResultFromToken(ctx context.Context, authParams authority.AuthParams, token accesstokens.TokenResponse) (AuthResult, error)

func (Client) RemoveAccount added in v0.3.0

func (b Client) RemoveAccount(ctx context.Context, account shared.Account) error

RemoveAccount removes all the ATs, RTs and IDTs from the cache associated with this account.

type Option

type Option func(c *Client) error

Option is an optional argument to the New constructor.

func WithCacheAccessor

func WithCacheAccessor(ca cache.ExportReplace) Option

WithCacheAccessor allows you to set some type of cache for storing authentication tokens.

func WithClientCapabilities added in v0.8.0

func WithClientCapabilities(capabilities []string) Option

WithClientCapabilities allows configuring one or more client capabilities such as "CP1"

func WithInstanceDiscovery added in v0.8.0

func WithInstanceDiscovery(instanceDiscoveryEnabled bool) Option

func WithKnownAuthorityHosts added in v0.7.0

func WithKnownAuthorityHosts(hosts []string) Option

WithKnownAuthorityHosts specifies hosts Client shouldn't validate or request metadata for because they're known to the user

func WithRegionDetection added in v0.5.0

func WithRegionDetection(region string) Option

func WithX5C

func WithX5C(sendX5C bool) Option

WithX5C specifies if x5c claim(public key of the certificate) should be sent to STS to enable Subject Name Issuer Authentication.

type TokenSource added in v1.2.3

type TokenSource int
const (
	TokenSourceIdentityProvider TokenSource = 0
	TokenSourceCache            TokenSource = 1
)

These are all the types of token flows.

Directories

Path Synopsis
Package storage holds all cached token information for MSAL.
Package storage holds all cached token information for MSAL.

Jump to

Keyboard shortcuts

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